This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-redback-core.git

commit b2d94281c6bfe6fbfe6738815092b9e097f03cb7
Author: Martin Stockhammer <[email protected]>
AuthorDate: Sun Jul 19 16:43:38 2020 +0200

    Switching V1 user service to old return values
---
 .../redback/rest/api/services/UserService.java     | 38 ++++++-----
 .../redback/rest/services/DefaultUserService.java  | 79 ++++++++++++----------
 .../rest/services/AbstractRestServicesTest.java    |  2 +-
 .../redback/rest/services/UserServiceTest.java     | 14 ++--
 4 files changed, 73 insertions(+), 60 deletions(-)

diff --git 
a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java
 
b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java
index 57291be..3dde14e 100644
--- 
a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java
+++ 
b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java
@@ -21,19 +21,14 @@ package org.apache.archiva.redback.rest.api.services;
 
 import org.apache.archiva.redback.authorization.RedbackAuthorization;
 import 
org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
-import org.apache.archiva.redback.rest.api.model.ActionStatus;
 import org.apache.archiva.redback.rest.api.model.AvailabilityStatus;
 import org.apache.archiva.redback.rest.api.model.Operation;
-import org.apache.archiva.redback.rest.api.model.PasswordStatus;
 import org.apache.archiva.redback.rest.api.model.Permission;
-import org.apache.archiva.redback.rest.api.model.PingResult;
 import org.apache.archiva.redback.rest.api.model.RegistrationKey;
 import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
 import org.apache.archiva.redback.rest.api.model.User;
 import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
-import org.apache.archiva.redback.rest.api.model.VerificationStatus;
 
-import javax.swing.*;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -71,7 +66,7 @@ public interface UserService
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_CREATE_OPERATION )
-    ActionStatus createUser( User user )
+    Boolean createUser( User user )
         throws RedbackServiceException;
 
 
@@ -83,14 +78,14 @@ public interface UserService
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noRestriction = true )
-    ActionStatus createAdminUser( User user )
+    Boolean createAdminUser( User user )
         throws RedbackServiceException;
 
     @Path( "isAdminUserExists" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( noRestriction = true )
-    AvailabilityStatus isAdminUserExists()
+    Boolean isAdminUserExists()
         throws RedbackServiceException;
 
 
@@ -98,14 +93,14 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION )
-    ActionStatus deleteUser( @PathParam( "userName" ) String username )
+    Boolean deleteUser( @PathParam( "userName" ) String username )
         throws RedbackServiceException;
 
     @Path( "updateUser" )
     @POST
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
-    ActionStatus updateUser( User user )
+    Boolean updateUser( User user )
         throws RedbackServiceException;
 
     /**
@@ -115,7 +110,7 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
-    ActionStatus lockUser( @PathParam( "username" ) String username )
+    Boolean lockUser( @PathParam( "username" ) String username )
         throws RedbackServiceException;
 
     /**
@@ -125,7 +120,7 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
-    ActionStatus unlockUser( @PathParam( "username" ) String username )
+    Boolean unlockUser( @PathParam( "username" ) String username )
         throws RedbackServiceException;
 
 
@@ -136,10 +131,19 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
-    PasswordStatus passwordChangeRequired( @PathParam( "username" ) String 
username )
+    Boolean passwordChangeRequired( @PathParam( "username" ) String username )
         throws RedbackServiceException;
 
     /**
+     * @since 2.0
+     */
+    @Path( "passwordChangeNotRequired/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    Boolean passwordChangeNotRequired( @PathParam( "username" ) String 
username )
+        throws RedbackServiceException;
+    /**
      * update only the current user and this fields: fullname, email, password.
      * the service verify the curent logged user with the one passed in the 
method
      * @since 1.4
@@ -148,7 +152,7 @@ public interface UserService
     @POST
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( noRestriction = false, noPermission = true )
-    ActionStatus updateMe( User user )
+    Boolean updateMe( User user )
         throws RedbackServiceException;
 
     @Path( "ping" )
@@ -162,7 +166,7 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
-    ActionStatus removeFromCache( @PathParam( "userName" ) String username )
+    int removeFromCache( @PathParam( "userName" ) String username )
         throws RedbackServiceException;
 
     @Path( "getGuestUser" )
@@ -201,7 +205,7 @@ public interface UserService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( noRestriction = true, noPermission = true )
-    VerificationStatus validateUserFromKey( @PathParam( "key" ) String key )
+    Boolean validateUserFromKey( @PathParam( "key" ) String key )
         throws RedbackServiceException;
 
     /**
@@ -214,7 +218,7 @@ public interface UserService
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, 
MediaType.TEXT_PLAIN } )
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noRestriction = true, noPermission = true )
-    ActionStatus resetPassword( ResetPasswordRequest resetPasswordRequest )
+    Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
         throws RedbackServiceException;
 
     /**
diff --git 
a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
 
b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
index a1f05b1..c8adfbb 100644
--- 
a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
+++ 
b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
@@ -40,18 +40,14 @@ import org.apache.archiva.redback.rbac.RBACManager;
 import org.apache.archiva.redback.rbac.RbacManagerException;
 import org.apache.archiva.redback.rbac.UserAssignment;
 import org.apache.archiva.redback.rest.api.model.ActionStatus;
-import org.apache.archiva.redback.rest.api.model.AvailabilityStatus;
 import org.apache.archiva.redback.rest.api.model.ErrorMessage;
 import org.apache.archiva.redback.rest.api.model.Operation;
-import org.apache.archiva.redback.rest.api.model.PasswordStatus;
 import org.apache.archiva.redback.rest.api.model.Permission;
-import org.apache.archiva.redback.rest.api.model.PingResult;
 import org.apache.archiva.redback.rest.api.model.RegistrationKey;
 import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
 import org.apache.archiva.redback.rest.api.model.Resource;
 import org.apache.archiva.redback.rest.api.model.User;
 import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
-import org.apache.archiva.redback.rest.api.model.VerificationStatus;
 import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
 import org.apache.archiva.redback.rest.api.services.UserService;
 import org.apache.archiva.redback.rest.services.utils.PasswordValidator;
@@ -147,7 +143,7 @@ public class DefaultUserService
 
 
     @Override
-    public ActionStatus createUser( User user )
+    public Boolean createUser( User user )
         throws RedbackServiceException
     {
 
@@ -222,11 +218,11 @@ public class DefaultUserService
         {
             throw new RedbackServiceException( new ErrorMessage( 
e.getMessage() ) );
         }
-        return ActionStatus.SUCCESS;
+        return Boolean.TRUE;
     }
 
     @Override
-    public ActionStatus deleteUser( String username )
+    public Boolean deleteUser( String username )
         throws RedbackServiceException
     {
 
@@ -248,7 +244,7 @@ public class DefaultUserService
         try
         {
             userManager.deleteUser( username );
-            return ActionStatus.SUCCESS;
+            return Boolean.TRUE;
         }
         catch ( UserNotFoundException e )
         {
@@ -308,7 +304,7 @@ public class DefaultUserService
     }
 
     @Override
-    public ActionStatus updateMe( User user )
+    public Boolean updateMe( User user )
         throws RedbackServiceException
     {
         // check username == one in the session
@@ -375,11 +371,11 @@ public class DefaultUserService
 
         updateUser( realUser );
 
-        return ActionStatus.SUCCESS;
+        return Boolean.TRUE;
     }
 
     @Override
-    public ActionStatus updateUser( User user )
+    public Boolean updateUser( User user )
         throws RedbackServiceException
     {
         try
@@ -394,7 +390,7 @@ public class DefaultUserService
             rawUser.setPermanent( user.isPermanent() );
 
             userManager.updateUser( rawUser );
-            return ActionStatus.SUCCESS;
+            return Boolean.TRUE;
         }
         catch ( UserNotFoundException e )
         {
@@ -407,7 +403,7 @@ public class DefaultUserService
     }
 
     @Override
-    public ActionStatus removeFromCache( String userName )
+    public int removeFromCache( String userName )
         throws RedbackServiceException
     {
         if ( userAssignmentsCache != null )
@@ -433,7 +429,7 @@ public class DefaultUserService
             }
         }
 
-        return ActionStatus.SUCCESS;
+        return -1;
     }
 
     @Override
@@ -506,13 +502,13 @@ public class DefaultUserService
     }
 
     @Override
-    public ActionStatus createAdminUser( User adminUser )
+    public Boolean createAdminUser( User adminUser )
         throws RedbackServiceException
     {
-        if ( isAdminUserExists().isExists() )
+        if ( isAdminUserExists() )
         {
             log.warn( "Admin user exists already" );
-            return ActionStatus.FAIL;
+            return Boolean.FALSE;
         }
         log.debug("Creating admin admin user '{}'", adminUser.getUsername());
         if 
(!RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME.equals(adminUser.getUsername()))
 {
@@ -543,17 +539,17 @@ public class DefaultUserService
         {
             throw new RedbackServiceException( new ErrorMessage( 
e.getMessage() ) );
         }
-        return ActionStatus.SUCCESS;
+        return Boolean.TRUE;
     }
 
     @Override
-    public AvailabilityStatus isAdminUserExists()
+    public Boolean isAdminUserExists()
         throws RedbackServiceException
     {
         try
         {
             userManager.findUser( config.getString( 
UserConfigurationKeys.DEFAULT_ADMIN ) );
-            return new AvailabilityStatus( true );
+            return Boolean.TRUE;
         }
         catch ( UserNotFoundException e )
         {
@@ -565,15 +561,15 @@ public class DefaultUserService
 
             if ( cause != null && cause instanceof UserNotFoundException )
             {
-                return new AvailabilityStatus( false );
+                return Boolean.FALSE;
             }
             throw new RedbackServiceException( new ErrorMessage( 
e.getMessage() ) );
         }
-        return new AvailabilityStatus( false );
+        return Boolean.FALSE;
     }
 
     @Override
-    public ActionStatus resetPassword( ResetPasswordRequest 
resetPasswordRequest )
+    public Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
         throws RedbackServiceException
     {
         String username = resetPasswordRequest.getUsername();
@@ -617,7 +613,7 @@ public class DefaultUserService
             throw new RedbackServiceException( new ErrorMessage( 
e.getMessage() ) );
         }
 
-        return ActionStatus.SUCCESS;
+        return Boolean.TRUE;
     }
 
     @Override
@@ -736,7 +732,7 @@ public class DefaultUserService
     }
 
     @Override
-    public VerificationStatus validateUserFromKey( String key )
+    public Boolean validateUserFromKey( String key )
         throws RedbackServiceException
     {
         String principal = null;
@@ -765,7 +761,7 @@ public class DefaultUserService
 
             log.info( "account validated for user {}", user.getUsername() );
 
-            return new VerificationStatus( true );
+            return Boolean.TRUE;
         }
         catch ( MustChangePasswordException | AccountLockedException | 
AuthenticationException e )
         {
@@ -976,7 +972,7 @@ public class DefaultUserService
     }
 
     @Override
-    public ActionStatus unlockUser( String username )
+    public Boolean unlockUser( String username )
         throws RedbackServiceException
     {
         User user = getUser( username );
@@ -984,13 +980,13 @@ public class DefaultUserService
         {
             user.setLocked( false );
             updateUser( user );
-            return ActionStatus.SUCCESS;
+            return Boolean.TRUE;
         }
-        return ActionStatus.FAIL;
+        return Boolean.FALSE;
     }
 
     @Override
-    public ActionStatus lockUser( String username )
+    public Boolean lockUser( String username )
         throws RedbackServiceException
     {
         User user = getUser( username );
@@ -998,13 +994,13 @@ public class DefaultUserService
         {
             user.setLocked( true );
             updateUser( user );
-            return ActionStatus.SUCCESS;
+            return Boolean.TRUE;
         }
-        return ActionStatus.FAIL;
+        return Boolean.FALSE;
     }
 
     @Override
-    public PasswordStatus passwordChangeRequired( String username )
+    public Boolean passwordChangeRequired( String username )
         throws RedbackServiceException
     {
         User user = getUser( username );
@@ -1012,9 +1008,22 @@ public class DefaultUserService
         {
             user.setPasswordChangeRequired( true );
             updateUser( user );
-            return new PasswordStatus( true );
+            return Boolean.TRUE;
         }
-        return new PasswordStatus( false );
+        return Boolean.FALSE;
     }
 
+    @Override
+    public Boolean passwordChangeNotRequired( String username )
+        throws RedbackServiceException
+    {
+        User user = getUser( username );
+        if ( user == null )
+        {
+            user.setPasswordChangeRequired( false );
+            updateUser( user );
+            return Boolean.TRUE;
+        }
+        return Boolean.FALSE;
+    }
 }
diff --git 
a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
 
b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
index f402ead..839f8e7 100644
--- 
a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
+++ 
b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
@@ -167,7 +167,7 @@ public abstract class AbstractRestServicesTest
         adminUser.setPassword( BaseSetup.getAdminPwd() );
         adminUser.setFullName( "the admin user" );
         adminUser.setEmail( "[email protected]" );
-        if( !userService.createAdminUser( adminUser ).isSuccess( ) ) {
+        if( !userService.createAdminUser( adminUser ) ) {
             log.info( "Could not create admin user." );
         }
 
diff --git 
a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
 
b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
index ba5a78e..2e262ea 100644
--- 
a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
+++ 
b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java
@@ -167,7 +167,7 @@ public class UserServiceTest
             assertTrue( messageContent.contains( "http://wine.fr/bordeaux"; ) );
             assertTrue( messageContent.contains( "toto" ) );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
             service = getUserService( authorizationHeader );
 
@@ -177,7 +177,7 @@ public class UserServiceTest
             assertTrue( u.isValidated() );
             assertTrue( u.isPasswordChangeRequired() );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
         }
         catch ( Exception e )
@@ -227,7 +227,7 @@ public class UserServiceTest
             assertTrue(messageContent.contains("http://localhost:"; + 
getServerPort() ));
             assertTrue( messageContent.toLowerCase( ).contains( "toto" ) );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
             service = getUserService( authorizationHeader );
 
@@ -237,7 +237,7 @@ public class UserServiceTest
             assertTrue( u.isValidated() );
             assertTrue( u.isPasswordChangeRequired() );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
         }
         catch ( Exception e )
@@ -285,7 +285,7 @@ public class UserServiceTest
             assertTrue(
                 emailMessages.get( 0 ).getText().contains( "Use the following 
URL to validate your account." ) );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
             service = getUserService( authorizationHeader );
 
@@ -295,9 +295,9 @@ public class UserServiceTest
             assertTrue( u.isValidated() );
             assertTrue( u.isPasswordChangeRequired() );
 
-            assertTrue( service.validateUserFromKey( key ).isSuccess() );
+            assertTrue( service.validateUserFromKey( key ) );
 
-            assertTrue( service.resetPassword( new ResetPasswordRequest( 
"toto", "http://foo.fr/bar"; ) ).isSuccess() );
+            assertTrue( service.resetPassword( new ResetPasswordRequest( 
"toto", "http://foo.fr/bar"; ) ) );
 
             emailMessages = assertService.getEmailMessageSended();
             assertEquals( 2, emailMessages.size() );

Reply via email to