Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Expired Password identification API #475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023, 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.expired.password.identification</artifactId>
<version>1.2.76-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.expired.password.identification.common</artifactId>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>org.wso2.carbon.identity.password.expiry</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023, 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.common;

import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
import org.wso2.carbon.identity.core.util.IdentityUtil;

/**
* Load information from context.
*/
public class ContextLoader {

/**
* Retrieves loaded tenant domain from carbon context.
*
* @return tenant domain of the request is being served.
*/
public static String getTenantDomainFromContext() {

String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
if (IdentityUtil.threadLocalProperties.get().get(IdentityCoreConstants.TENANT_NAME_FROM_CONTEXT) != null) {
tenantDomain = (String) IdentityUtil.threadLocalProperties.get()
.get(IdentityCoreConstants.TENANT_NAME_FROM_CONTEXT);
}
return tenantDomain;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2023, 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.common;

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

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

private static ExpiredPasswordIdentificationService expiredPasswordIdentificationService;

/**
* 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023, 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.common.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.password.expiry.services.ExpiredPasswordIdentificationService;

/**
* Factory Beans serve as a factory for creating other beans within the IOC container. This factory bean is used to
* instantiate the ExpiredPasswordIdentificationService type of object inside the container.
*/
public class ExpiredPasswordIdentificationOSGIServiceFactory
extends AbstractFactoryBean<ExpiredPasswordIdentificationService> {

private ExpiredPasswordIdentificationService expiredPasswordIdentificationService;

@Override
public Class<?> getObjectType() {

return Object.class;
}

@Override
protected ExpiredPasswordIdentificationService createInstance() throws Exception {

if (this.expiredPasswordIdentificationService == null) {
ExpiredPasswordIdentificationService taskOperationService =
(ExpiredPasswordIdentificationService) PrivilegedCarbonContext.
getThreadLocalCarbonContext().getOSGiService(ExpiredPasswordIdentificationService.class, null);

if (taskOperationService == null) {
throw new Exception("Unable to retrieve expired password identification service.");
}
this.expiredPasswordIdentificationService = taskOperationService;
}
return this.expiredPasswordIdentificationService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2023, 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.common.util;

/**
* Password expired users identification related constant class.
*/
public class ExpiredPasswordIdentificationConstants {

public static final String EXPIRED_PASSWORD_IDENTIFICATION_MANAGEMENT_SERVICE_ERROR_PREFIX = "PASS-EXP_ACC-";
public static final String DATE_EXPIRED_AFTER = "expiredAfter";
public static final String DATE_EXCLUDE_AFTER = "excludeAfter";
public static final String DATE_FORMAT_REGEX = "^\\d{4}-\\d{2}-\\d{2}$";

/**
* Enums for error messages.
*/
public enum ErrorMessage {

// Client errors 600xx.
ERROR_REQUIRED_PARAMETER_MISSING("60001",
"Required parameter is not provided.",
"%s parameter is required and cannot be empty."),

ERROR_DATE_REGEX_MISMATCH("60002",
"Invalid date format provided.",
"The value provided for %s parameter is invalid. Date format should be yyyy-mm-dd."),

ERROR_INVALID_DATE("60003",
"Invalid date provided.",
"The date provided for %s parameter is invalid."),
PASSWORD_EXPIRY_FEATURE_NOT_ENABLED("60004",
"The password expiry feature is not enabled.",
"The password expiry feature needs to be enabled to retrieve the password expired users."),

// Server errors 650xx.
ERROR_RETRIEVING_PASSWORD_EXPIRED_USERS("65001",
"Error while retrieving password expired users.",
"Error while retrieving password expired users for organization: %s.");

private final String code;
private final String message;
private final String description;

ErrorMessage(String code, String message, String description) {

this.code = code;
this.message = message;
this.description = description;
}

public String getCode() {

return EXPIRED_PASSWORD_IDENTIFICATION_MANAGEMENT_SERVICE_ERROR_PREFIX + code;
}

public String getMessage() {

return message;
}

public String getDescription() {

return description;
}

@Override
public String toString() {

return code + " | " + message;
}
}
}
Loading
Loading