From 93b1f170ff9b6e0eb7719071bd81efc7369bcd64 Mon Sep 17 00:00:00 2001 From: dongxiancun Date: Fri, 26 Jul 2019 11:40:38 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20aaa-12=20=E6=8F=90=E9=AB=98=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E8=A6=86=E7=9B=96=E7=8E=87=20RCA?= =?UTF-8?q?=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?dongxiancun=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Adongxiancun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ControlPlatform/aaa/aaa-shiro/impl/pom.xml | 9 -- .../aaa/shiro/idm/UserHandler.java | 83 +++++++------------ .../shiro/idm/rest/test/UserHandlerTest.java | 40 ++++----- ControlPlatform/aaa/parent/pom.xml | 5 -- 4 files changed, 51 insertions(+), 86 deletions(-) diff --git a/ControlPlatform/aaa/aaa-shiro/impl/pom.xml b/ControlPlatform/aaa/aaa-shiro/impl/pom.xml index 83622d57b..71e68b848 100644 --- a/ControlPlatform/aaa/aaa-shiro/impl/pom.xml +++ b/ControlPlatform/aaa/aaa-shiro/impl/pom.xml @@ -251,15 +251,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - - org.jacoco - jacoco-maven-plugin - - - **/*UserHandler.* - - - diff --git a/ControlPlatform/aaa/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/UserHandler.java b/ControlPlatform/aaa/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/UserHandler.java index 5e86df2a9..e92978a53 100644 --- a/ControlPlatform/aaa/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/UserHandler.java +++ b/ControlPlatform/aaa/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/UserHandler.java @@ -14,21 +14,7 @@ package org.opendaylight.aaa.shiro.idm; -import java.util.Collection; -import java.util.Objects; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; import org.opendaylight.aaa.api.ClaimCache; -import org.opendaylight.aaa.AAAShiroProvider; import org.opendaylight.aaa.api.IDMStoreException; import org.opendaylight.aaa.api.IIDMStore; import org.opendaylight.aaa.api.model.IDMError; @@ -37,7 +23,14 @@ import org.opendaylight.aaa.api.model.Users; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -58,7 +51,7 @@ import java.util.Objects; public class UserHandler { private static final Logger LOG = LoggerFactory.getLogger(UserHandler.class); - private static final String PW_PATTERN = "/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{8,}$/"; + private static final String PW_PATTERN = "^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{8,}$"; /** * If a user is created through the /auth/v1/users rest * endpoint without a password, the default password is assigned to the @@ -129,10 +122,9 @@ public class UserHandler { * Extracts the user represented by id. The password and salt * fields are redacted for security reasons. * - * @param id - * the unique id of representing the user account + * @param id the unique id of representing the user account * @return A response with the user information, or internal error if one - * occurs + * occurs */ @GET @Path("/{id}") @@ -170,10 +162,8 @@ public class UserHandler { * If a password is not provided, please ensure you change the default * password ASAP for security reasons! * - * @param info - * passed from Jersey - * @param user - * the user defined in the JSON payload + * @param info passed from Jersey + * @param user the user defined in the JSON payload * @return A response stating success or failure of user creation */ @POST @@ -220,7 +210,7 @@ public class UserHandler { String userDescription = user.getDescription(); if (userDescription == null) { user.setDescription(DEFAULT_DESCRIPTION); - } else if (userDescription.length() > IdmLightApplication.MAX_FIELD_LEN) { + } else if (userDescription.length() > IdmLightApplication.MAX_FIELD_LEN) { // The "description" field has a maximum length. return providedFieldTooLong("description", IdmLightApplication.MAX_FIELD_LEN); } @@ -242,7 +232,7 @@ public class UserHandler { return providedFieldTooLong("password", IdmLightApplication.MAX_FIELD_LEN); } - Response response = checkPasswordError(userPassword); + Response response = checkPasswordError(userPassword); if (response.getStatus() != 200) { return response; } @@ -278,15 +268,13 @@ public class UserHandler { private Response providePasswordError(String s) { return new IDMError(407, s).response(); } + /** * REST endpoint to update a user account. * - * @param info - * passed from Jersey - * @param user - * the user defined in the JSON payload - * @param id - * the unique id for the user that will be updated + * @param info passed from Jersey + * @param user the user defined in the JSON payload + * @param id the unique id for the user that will be updated * @return A response stating success or failure of the user update */ @PUT @@ -338,10 +326,8 @@ public class UserHandler { /** * REST endpoint to delete a user account. * - * @param info - * passed from Jersey - * @param id - * the unique id of the user which is being deleted + * @param info passed from Jersey + * @param id the unique id of the user which is being deleted * @return A response stating success or failure of user deletion */ @DELETE @@ -368,10 +354,8 @@ public class UserHandler { /** * Creates a Response related to an internal server error. * - * @param verbal - * such as "creating", "deleting", "updating" - * @param ex - * The exception, which is logged locally + * @param verbal such as "creating", "deleting", "updating" + * @param ex The exception, which is logged locally * @return A response containing internal error with specific reasoning */ private Response internalError(final String verbal, final Exception ex) { @@ -384,8 +368,7 @@ public class UserHandler { * Creates a Response related to the user not providing a * required field. * - * @param fieldName - * the name of the field which is missing + * @param fieldName the name of the field which is missing * @return A response explaining that the request is missing a field */ private Response missingRequiredField(final String fieldName) { @@ -400,10 +383,8 @@ public class UserHandler { * Creates a Response related to the user providing a field * that is too long. * - * @param fieldName - * the name of the field that is too long - * @param maxFieldLength - * the maximum length of fieldName + * @param fieldName the name of the field that is too long + * @param maxFieldLength the maximum length of fieldName * @return A response containing the bad field and the maximum field length */ private Response providedFieldTooLong(final String fieldName, final int maxFieldLength) { @@ -414,10 +395,8 @@ public class UserHandler { * Creates the client-facing message related to the user providing a field * that is too long. * - * @param fieldName - * the name of the field that is too long - * @param maxFieldLength - * the maximum length of fieldName + * @param fieldName the name of the field that is too long + * @param maxFieldLength the maximum length of fieldName * @return a response containing the too long field and its length */ private static String getProvidedFieldTooLongMessage(final String fieldName, final int maxFieldLength) { @@ -430,8 +409,7 @@ public class UserHandler { * Prepares a user account for output by redacting the appropriate fields. * This method side-effects the user parameter. * - * @param user - * the user account which will have fields redacted + * @param user the user account which will have fields redacted */ private static void redactUserPasswordInfo(final User user) { user.setPassword(REDACTED_PASSWORD); @@ -441,8 +419,7 @@ public class UserHandler { /** * Validate the input field length. * - * @param inputField - * the field to check + * @param inputField the field to check * @return true if input field bigger than the MAX_FIELD_LEN */ private boolean checkInputFieldLength(final String inputField) { diff --git a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/UserHandlerTest.java b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/UserHandlerTest.java index 29afa90da..857a83a8c 100644 --- a/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/UserHandlerTest.java +++ b/ControlPlatform/aaa/aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/UserHandlerTest.java @@ -14,24 +14,24 @@ package org.opendaylight.aaa.shiro.idm.rest.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.ws.rs.NotFoundException; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; import org.junit.Ignore; import org.junit.Test; import org.opendaylight.aaa.api.model.IDMError; import org.opendaylight.aaa.api.model.User; import org.opendaylight.aaa.api.model.Users; -@Ignore +import javax.ws.rs.NotFoundException; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + public class UserHandlerTest extends HandlerTest { @Test @@ -61,12 +61,14 @@ public class UserHandlerTest extends HandlerTest { // check create user Map usrData = new HashMap<>(); usrData.put("name", "usr1"); - usrData.put("description", "test user"); - usrData.put("enabled", "true"); +// usrData.put("description", "test user"); +// usrData.put("enabled", "true"); usrData.put("email", "user1@usr.org"); usrData.put("password", "ChangeZbadPa$$w0rd"); usrData.put("domainid", "0"); - Response clientResponse = target("/v1/users").request().post(entity(usrData)); + Response clientResponse = target("/v1/users") + .request() + .post(entity(usrData)); assertEquals(201, clientResponse.getStatus()); // check create user missing name data @@ -101,8 +103,8 @@ public class UserHandlerTest extends HandlerTest { // Bug 8382: if a user id is specified, 400 is returned usrData = new HashMap<>(); usrData.put("name", "usr1"); - usrData.put("description", "test user"); - usrData.put("enabled", "true"); +// usrData.put("description", "test user"); +// usrData.put("enabled", "true"); usrData.put("email", "user1@usr.org"); usrData.put("password", "ChangeZbadPa$$w0rd"); usrData.put("userid", "userid"); @@ -113,10 +115,10 @@ public class UserHandlerTest extends HandlerTest { } /** * Revision history - * + *

* ------------------------------------------------------------------------- * Date Author Note - * + *

* ------------------------------------------------------------------------- * 2019/7/3 Dong Xiancun creat */ diff --git a/ControlPlatform/aaa/parent/pom.xml b/ControlPlatform/aaa/parent/pom.xml index 0e504587c..39bbe1074 100644 --- a/ControlPlatform/aaa/parent/pom.xml +++ b/ControlPlatform/aaa/parent/pom.xml @@ -139,11 +139,6 @@ - - - **/*UserHandler.* - -