Skip to content

Commit

Permalink
Merge pull request #786 from lashinijay/master-revamp-expired-password
Browse files Browse the repository at this point in the history
[Spring Cleanup] Remove Spring dependencies in password expired user management API
  • Loading branch information
lashinijay authored Jan 24, 2025
2 parents 2a7420b + ceda588 commit 3225bb0
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
<artifactId>cxf-rt-rs-service-description</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@

package org.wso2.carbon.identity.api.expired.password.identification.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.password.expiry.services.ExpiredPasswordIdentificationService;

/**
* Service holder class for password expired users identification.
*/
public class PasswordExpiryServiceHolder {

private static ExpiredPasswordIdentificationService expiredPasswordIdentificationService;
private PasswordExpiryServiceHolder() {}

private static class ExpiredPasswordIdentificationServiceHolder {
static final ExpiredPasswordIdentificationService SERVICE =
(ExpiredPasswordIdentificationService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(ExpiredPasswordIdentificationService.class, null);
}

/**
* Get ExpiredPasswordIdentificationService OSGi service.
*
* @return ExpiredPassword identification Service.
*/
public static ExpiredPasswordIdentificationService getExpiredPasswordIdentificationService() {

return expiredPasswordIdentificationService;
}

/**
* Set ExpiredPasswordIdentificationService OSGi service.
*
* @param expiredPasswordIdentificationService ExpiredPassword identification Service.
*/
public static void setExpiredPasswordIdentificationService(
ExpiredPasswordIdentificationService expiredPasswordIdentificationService) {

PasswordExpiryServiceHolder.expiredPasswordIdentificationService = expiredPasswordIdentificationService;
return ExpiredPasswordIdentificationServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@
<artifactId>cxf-rt-rs-service-description</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@

package org.wso2.carbon.identity.api.expired.password.identification.v1;

import org.springframework.beans.factory.annotation.Autowired;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import java.io.InputStream;
import java.util.List;

import org.wso2.carbon.identity.api.expired.password.identification.v1.factories.PasswordExpiredUsersApiServiceFactory;
import org.wso2.carbon.identity.api.expired.password.identification.v1.model.Error;
import org.wso2.carbon.identity.api.expired.password.identification.v1.model.PasswordExpiredUser;
import org.wso2.carbon.identity.api.expired.password.identification.v1.model.Unauthorized;
import org.wso2.carbon.identity.api.expired.password.identification.v1.PasswordExpiredUsersApiService;

import javax.validation.Valid;
import javax.ws.rs.*;
Expand All @@ -41,8 +35,12 @@

public class PasswordExpiredUsersApi {

@Autowired
private PasswordExpiredUsersApiService delegate;
private final PasswordExpiredUsersApiService delegate;

public PasswordExpiredUsersApi() {

this.delegate = PasswordExpiredUsersApiServiceFactory.getPasswordExpiredUsersApi();
}

@Valid
@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
import org.wso2.carbon.identity.api.expired.password.identification.v1.PasswordExpiredUsersApiService;
import org.wso2.carbon.identity.api.expired.password.identification.v1.impl.PasswordExpiredUsersApiServiceImpl;

/**
* Factory class for PasswordExpiredUsersApiService.
*/
public class PasswordExpiredUsersApiServiceFactory {

private final static PasswordExpiredUsersApiService service = new PasswordExpiredUsersApiServiceImpl();
private final static PasswordExpiredUsersApiService SERVICE = new PasswordExpiredUsersApiServiceImpl();

/**
* Get PasswordExpiredUsersApiService.
*
* @return PasswordExpiredUsersApiService.
*/
public static PasswordExpiredUsersApiService getPasswordExpiredUsersApi() {

public static PasswordExpiredUsersApiService getPasswordExpiredUsersApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.api.expired.password.identification.common.PasswordExpiryServiceHolder;
import org.wso2.carbon.identity.api.expired.password.identification.common.util.ExpiredPasswordIdentificationConstants.ErrorMessage;
import org.wso2.carbon.identity.api.expired.password.identification.v1.model.PasswordExpiredUser;
import org.wso2.carbon.identity.api.server.common.error.APIError;
Expand All @@ -31,6 +30,7 @@
import org.wso2.carbon.identity.password.expiry.exceptions.ExpiredPasswordIdentificationException;
import org.wso2.carbon.identity.password.expiry.exceptions.ExpiredPasswordIdentificationServerException;
import org.wso2.carbon.identity.password.expiry.models.PasswordExpiredUserModel;
import org.wso2.carbon.identity.password.expiry.services.ExpiredPasswordIdentificationService;
import org.wso2.carbon.identity.password.expiry.util.PasswordPolicyUtils;

import java.time.LocalDate;
Expand All @@ -51,8 +51,15 @@
*/
public class PasswordExpiredUsersManagementApiService {

private final ExpiredPasswordIdentificationService expiredPasswordIdentificationService;
private static final Log LOG = LogFactory.getLog(PasswordExpiredUsersManagementApiService.class);

public PasswordExpiredUsersManagementApiService(
ExpiredPasswordIdentificationService expiredPasswordIdentificationService) {

this.expiredPasswordIdentificationService = expiredPasswordIdentificationService;
}

/**
* Get password expired users.
*
Expand All @@ -71,11 +78,11 @@ public List<PasswordExpiredUser> getPasswordExpiredUsers(
LocalDateTime expiredAfterDate = convertToDateObject(expiredAfter, DATE_EXPIRED_AFTER);
LocalDateTime excludeAfterDate = convertToDateObject(excludeAfter, DATE_EXCLUDE_AFTER);
if (excludeAfterDate == null) {
passwordExpiredUsers = PasswordExpiryServiceHolder.getExpiredPasswordIdentificationService().
getPasswordExpiredUsersFromSpecificDate(expiredAfterDate, tenantDomain);
passwordExpiredUsers = expiredPasswordIdentificationService
.getPasswordExpiredUsersFromSpecificDate(expiredAfterDate, tenantDomain);
} else {
passwordExpiredUsers = PasswordExpiryServiceHolder.getExpiredPasswordIdentificationService().
getPasswordExpiredUsersBetweenSpecificDates(expiredAfterDate, excludeAfterDate, tenantDomain);
passwordExpiredUsers = expiredPasswordIdentificationService
.getPasswordExpiredUsersBetweenSpecificDates(expiredAfterDate, excludeAfterDate, tenantDomain);
}
return buildResponse(passwordExpiredUsers);
} catch (ExpiredPasswordIdentificationException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.expired.password.identification.v1.factories;

import org.wso2.carbon.identity.api.expired.password.identification.common.PasswordExpiryServiceHolder;
import org.wso2.carbon.identity.api.expired.password.identification.v1.core.PasswordExpiredUsersManagementApiService;
import org.wso2.carbon.identity.password.expiry.services.ExpiredPasswordIdentificationService;

/**
* Factory class for PasswordExpiredUsersManagementApiService.
*/
public class PasswordExpiredUsersManagementApiServiceFactory {

private static final PasswordExpiredUsersManagementApiService SERVICE;

static {
ExpiredPasswordIdentificationService expiredPasswordIdentificationService =
PasswordExpiryServiceHolder.getExpiredPasswordIdentificationService();

if (expiredPasswordIdentificationService == null) {
throw new IllegalStateException("RolePermissionManagementService is not available from OSGi context.");
}

SERVICE = new PasswordExpiredUsersManagementApiService(expiredPasswordIdentificationService);
}

/**
* Get PasswordExpiredUsersManagementApiService service instance.
*
* @return PasswordExpiredUsersManagementApiService service.
*/
public static PasswordExpiredUsersManagementApiService getExpiredPasswordIdentificationService() {

return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package org.wso2.carbon.identity.api.expired.password.identification.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.expired.password.identification.common.ContextLoader;
import org.wso2.carbon.identity.api.expired.password.identification.v1.PasswordExpiredUsersApiService;
import org.wso2.carbon.identity.api.expired.password.identification.v1.core.PasswordExpiredUsersManagementApiService;
import org.wso2.carbon.identity.api.expired.password.identification.v1.factories.PasswordExpiredUsersManagementApiServiceFactory;

import javax.ws.rs.core.Response;

Expand All @@ -30,8 +30,17 @@
*/
public class PasswordExpiredUsersApiServiceImpl implements PasswordExpiredUsersApiService {

@Autowired
private PasswordExpiredUsersManagementApiService passwordExpiredUsersManagementApiService;
private final PasswordExpiredUsersManagementApiService passwordExpiredUsersManagementApiService;

public PasswordExpiredUsersApiServiceImpl() {

try {
this.passwordExpiredUsersManagementApiService = PasswordExpiredUsersManagementApiServiceFactory
.getExpiredPasswordIdentificationService();
} catch (IllegalStateException e) {
throw new RuntimeException("Error occurred while initiating password expired users management service.", e);
}
}

@Override
public Response getPasswordExpiredUsers(String expiredAfter, String excludeAfter) {
Expand Down

This file was deleted.

0 comments on commit 3225bb0

Please sign in to comment.