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 Pre Update Password action management related files #6281

Merged
merged 19 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
afa989b
Add Pre Update Password action management related files
ashanthamara Jan 13, 2025
12871d2
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 21, 2025
aa6d6cf
Rename feature module name
ashanthamara Jan 21, 2025
69c42f3
Add Unit test for ActionConverter
ashanthamara Jan 22, 2025
f98540a
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 23, 2025
36f70f4
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 24, 2025
861e28b
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 24, 2025
3cfd441
Add unit test for PreUpdatePasswordActionDTOModelResolver and refacto…
ashanthamara Jan 25, 2025
07baa92
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 25, 2025
31de195
Minor changes
ashanthamara Jan 25, 2025
e0969aa
Address sonarcube suggestions
ashanthamara Jan 25, 2025
604c0ad
Address comments
ashanthamara Jan 25, 2025
e1d2c83
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 25, 2025
7efdf6a
Fix component version
ashanthamara Jan 25, 2025
415638b
Error message fix
ashanthamara Jan 25, 2025
9426492
Fix package exposing issues
ashanthamara Jan 25, 2025
4154fdf
Minor fix
ashanthamara Jan 25, 2025
08e0c5b
Merge remote-tracking branch 'upstream/master' into pre-update-password
ashanthamara Jan 25, 2025
2e2c319
Update component version
ashanthamara Jan 25, 2025
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
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
Loading