Skip to content

Commit

Permalink
Merge pull request #6281 from ashanthamara/pre-update-password
Browse files Browse the repository at this point in the history
Add Pre Update Password action management related files
  • Loading branch information
ashanthamara authored Jan 25, 2025
2 parents 35e9652 + 2e2c319 commit a752ab1
Show file tree
Hide file tree
Showing 21 changed files with 1,956 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ private ActionRule populateRule(Map<String, String> propertiesFromDB, Integer te
private void addProperties(ActionDTO actionDTO, Integer tenantId) throws ActionMgtException {

Map<String, Object> propertiesMap = actionDTO.getProperties();
if (propertiesMap == null) {
if (propertiesMap == null || propertiesMap.isEmpty()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.wso2.carbon.identity.action.management.model.ActionDTO;

/**
* This interface defines the Action ActionConverter.
* This interface defines the Action ActionConverter executed in the Action management service layer.
* Action ActionConverter is the component that is responsible for the conversions between Action and ExtendedAction
* objects.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.List;

/**
* This interface defines the Action Property Resolver.
* This interface defines the Action Property Resolver executed in the Action management dao facade layer.
* Action Property Resolver is the component that is responsible for handling action type specific operations.
*/
public interface ActionDTOModelResolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Action activateAction(String actionType, String actionId, String tenantDo
ActionDTO activatedActionDTO = DAO_FACADE.activateAction(resolvedActionType, actionId,
IdentityTenantUtil.getTenantId(tenantDomain));
auditLogger.printAuditLog(ActionManagementAuditLogger.Operation.ACTIVATE, actionType, actionId);
return buildAction(resolvedActionType, activatedActionDTO);
return buildBasicAction(activatedActionDTO);
}

/**
Expand All @@ -227,7 +227,7 @@ public Action deactivateAction(String actionType, String actionId, String tenant
ActionDTO deactivatedActionDTO = DAO_FACADE.deactivateAction(resolvedActionType, actionId,
IdentityTenantUtil.getTenantId(tenantDomain));
auditLogger.printAuditLog(ActionManagementAuditLogger.Operation.DEACTIVATE, actionType, actionId);
return buildAction(resolvedActionType, deactivatedActionDTO);
return buildBasicAction(deactivatedActionDTO);
}

/**
Expand Down Expand Up @@ -418,6 +418,21 @@ private ActionDTO buildActionDTO(String actionType, String actionId, Action acti
.build();
}

private Action buildBasicAction(ActionDTO actionDTO) {

if (actionDTO == null) {
return null;
}

return new Action.ActionResponseBuilder()
.id(actionDTO.getId())
.type(actionDTO.getType())
.name(actionDTO.getName())
.description(actionDTO.getDescription())
.status(actionDTO.getStatus())
.build();
}

private Action buildAction(String actionType, ActionDTO actionDTO) {

if (actionDTO == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<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">
<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>user-mgt</artifactId>
<version>7.7.138-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.identity.user.pre.update.password.action</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Pre Update Password Action Service</name>
<description>The Pre Update Password Action Service backend component</description>
<url>http://wso2.org</url>

<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.action.management</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.testutil</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${project.artifactId}
</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Private-Package>
org.wso2.carbon.identity.user.pre.update.password.action.core.constant,
org.wso2.carbon.identity.user.pre.update.password.action.core.management,
org.wso2.carbon.identity.user.pre.update.password.action.internal
</Private-Package>
<Export-Package>
org.wso2.carbon.identity.user.pre.update.password.action.service.*;
version="${carbon.identity.package.export.version}"
</Export-Package>
<Import-Package>
org.apache.commons.lang; version="${commons-lang.wso2.osgi.version.range}",
org.apache.commons.logging; version="${import.package.version.commons.logging}",
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}",
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}",
org.wso2.carbon.identity.action.management.exception; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.action.management.model; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.action.management.service; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.certificate.management.service; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.certificate.management.exception; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.certificate.management.model; version="${carbon.identity.package.import.version.range}"
</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<excludeFilterFile>../../../spotbugs-exclude.xml</excludeFilterFile>
<effort>Max</effort>
<threshold>High</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.user.pre.update.password.action.core.constant;

/**
* This class holds the constants used in Pre Update Password extension.
*/
public class PreUpdatePasswordActionConstants {

public static final String PASSWORD_SHARING_FORMAT = "passwordSharingFormat";
public static final String CERTIFICATE = "certificate";

private PreUpdatePasswordActionConstants() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.user.pre.update.password.action.core.management;

import org.wso2.carbon.identity.action.management.model.Action;
import org.wso2.carbon.identity.action.management.model.ActionDTO;
import org.wso2.carbon.identity.action.management.service.ActionConverter;
import org.wso2.carbon.identity.certificate.management.model.Certificate;
import org.wso2.carbon.identity.user.pre.update.password.action.service.model.PasswordSharing;
import org.wso2.carbon.identity.user.pre.update.password.action.service.model.PreUpdatePasswordAction;

import java.util.HashMap;
import java.util.Map;

import static org.wso2.carbon.identity.user.pre.update.password.action.core.constant.PreUpdatePasswordActionConstants.CERTIFICATE;
import static org.wso2.carbon.identity.user.pre.update.password.action.core.constant.PreUpdatePasswordActionConstants.PASSWORD_SHARING_FORMAT;

/**
* This class implements the methods required to build Action objects in Pre Update Password extension.
*/
public class PreUpdatePasswordActionConverter implements ActionConverter {

@Override
public Action.ActionTypes getSupportedActionType() {

return Action.ActionTypes.PRE_UPDATE_PASSWORD;
}

/**
* This method builds the ActionDTO object from the PreUpdatePasswordAction object in action creation and update.
*
* @param action PreUpdatePasswordAction object.
* @return ActionDTO object.
*
*/
@Override
public ActionDTO buildActionDTO(Action action) {

PreUpdatePasswordAction preUpdatePasswordAction = (PreUpdatePasswordAction) action;
PasswordSharing passwordSharing = preUpdatePasswordAction.getPasswordSharing();

Map<String, Object> properties = new HashMap<>();
if (passwordSharing != null && passwordSharing.getFormat() != null) {
properties.put(PASSWORD_SHARING_FORMAT, passwordSharing.getFormat());
}
if (passwordSharing != null && passwordSharing.getCertificate() != null) {
properties.put(CERTIFICATE, passwordSharing.getCertificate());
}

return new ActionDTO.Builder(preUpdatePasswordAction)
.properties(properties)
.build();
}

@Override
public Action buildAction(ActionDTO actionDTO) {

Map<String, Object> properties = actionDTO.getProperties();
PasswordSharing.Builder passwordSharingBuilder = new PasswordSharing.Builder();
passwordSharingBuilder.format((PasswordSharing.Format) actionDTO.getProperties().get(PASSWORD_SHARING_FORMAT));
if (properties.get(CERTIFICATE) != null) {
passwordSharingBuilder.certificate((Certificate) actionDTO.getProperties().get(CERTIFICATE));
}

return new PreUpdatePasswordAction.ResponseBuilder()
.id(actionDTO.getId())
.type(actionDTO.getType())
.name(actionDTO.getName())
.description(actionDTO.getDescription())
.status(actionDTO.getStatus())
.endpoint(actionDTO.getEndpoint())
.passwordSharing(passwordSharingBuilder.build())
.build();
}
}
Loading

0 comments on commit a752ab1

Please sign in to comment.