You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC

svn commit: r1310268 [13/42] - in /archiva/redback/redback-core/trunk: ./ redback-authentication/ redback-authentication/redback-authentication-api/ redback-authentication/redback-authentication-api/src/ redback-authentication/redback-authentication-ap...

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,309 @@
+package org.codehaus.redback.rest.api.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.
+ */
+
+import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
+import org.codehaus.redback.integration.security.role.RedbackRoleConstants;
+import org.codehaus.redback.rest.api.model.Application;
+import org.codehaus.redback.rest.api.model.ApplicationRoles;
+import org.codehaus.redback.rest.api.model.Role;
+import org.codehaus.redback.rest.api.model.User;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Path( "/roleManagementService/" )
+public interface RoleManagementService
+{
+
+    @Path( "createTemplatedRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean createTemplatedRole( @QueryParam( "templateId" ) String templateId,
+                                 @QueryParam( "resource" ) String resource )
+        throws RedbackServiceException;
+
+    /**
+     * removes a role corresponding to the role Id that was manufactured with the given resource
+     * <p/>
+     * it also removes any user assignments for that role
+     *
+     * @param templateId
+     * @param resource
+     * @throws Exception
+     */
+    @Path( "removeTemplatedRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean removeTemplatedRole( @QueryParam( "templateId" ) String templateId,
+                                 @QueryParam( "resource" ) String resource )
+        throws RedbackServiceException;
+
+
+    /**
+     * allows for a role coming from a template to be renamed effectively swapping out the bits of it that
+     * were labeled with the oldResource with the newResource
+     * <p/>
+     * it also manages any user assignments for that role
+     *
+     * @param templateId
+     * @param oldResource
+     * @param newResource
+     * @throws Exception
+     */
+    @Path( "updateRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean updateRole( @QueryParam( "templateId" ) String templateId, @QueryParam( "oldResource" ) String oldResource,
+                        @QueryParam( "newResource" ) String newResource )
+        throws RedbackServiceException;
+
+
+    /**
+     * Assigns the role indicated by the roleId to the given principal
+     *
+     * @param roleId
+     * @param principal
+     * @throws Exception
+     */
+    @Path( "assignRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean assignRole( @QueryParam( "roleId" ) String roleId, @QueryParam( "principal" ) String principal )
+        throws RedbackServiceException;
+
+    /**
+     * Assigns the role indicated by the roleName to the given principal
+     *
+     * @param roleName
+     * @param principal
+     * @throws Exception
+     */
+    @Path( "assignRoleByName" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean assignRoleByName( @QueryParam( "roleName" ) String roleName, @QueryParam( "principal" ) String principal )
+        throws RedbackServiceException;
+
+    /**
+     * Assigns the templated role indicated by the templateId
+     * <p/>
+     * fails if the templated role has not been created
+     *
+     * @param templateId
+     * @param resource
+     * @param principal
+     */
+    @Path( "assignTemplatedRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean assignTemplatedRole( @QueryParam( "templateId" ) String templateId,
+                                 @QueryParam( "resource" ) String resource,
+                                 @QueryParam( "principal" ) String principal )
+        throws RedbackServiceException;
+
+    /**
+     * Unassigns the role indicated by the role id from the given principal
+     *
+     * @param roleId
+     * @param principal
+     * @throws Exception
+     */
+    @Path( "unassignRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean unassignRole( @QueryParam( "roleId" ) String roleId, @QueryParam( "principal" ) String principal )
+        throws RedbackServiceException;
+
+    /**
+     * Unassigns the role indicated by the role name from the given principal
+     *
+     * @param roleName
+     * @param principal
+     * @throws Exception
+     */
+    @Path( "unassignRoleByName" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean unassignRoleByName( @QueryParam( "roleName" ) String roleName, @QueryParam( "principal" ) String principal )
+        throws RedbackServiceException;
+
+    /**
+     * true of a role exists with the given roleId
+     *
+     * @param roleId
+     * @return
+     * @throws Exception
+     */
+    @Path( "roleExists" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean roleExists( @QueryParam( "roleId" ) String roleId )
+        throws RedbackServiceException;
+
+    /**
+     * true of a role exists with the given roleId
+     *
+     * @param templateId
+     * @param resource
+     * @return
+     * @throws Exception
+     */
+    @Path( "templatedRoleExists" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean templatedRoleExists( @QueryParam( "templateId" ) String templateId,
+                                 @QueryParam( "resource" ) String resource )
+        throws RedbackServiceException;
+
+
+    /**
+     * Check a role template is complete in the RBAC store.
+     *
+     * @param templateId the templated role
+     * @param resource   the resource to verify
+     * @throws Exception
+     */
+    @Path( "verifyTemplatedRole" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    Boolean verifyTemplatedRole( @QueryParam( "templateId" ) String templateId,
+                                 @QueryParam( "resource" ) String resource )
+        throws RedbackServiceException;
+
+    @Path( "getEffectivelyAssignedRoles/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.4
+     */
+    List<Role> getEffectivelyAssignedRoles( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+
+    @Path( "allRoles" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    List<Role> getAllRoles()
+        throws RedbackServiceException;
+
+    @Path( "detailledAllRoles" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    List<Role> getDetailedAllRoles()
+        throws RedbackServiceException;
+
+
+    @Path( "getApplications/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    List<Application> getApplications( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+
+    @Path( "getRole/{roleName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Role getRole( @PathParam( "roleName" ) String roleName )
+        throws RedbackServiceException;
+
+    @Path( "updateRoleDescription" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Boolean updateRoleDescription( @QueryParam( "roleName" ) String roleName,
+                                   @QueryParam( "roleDescription" ) String description )
+        throws RedbackServiceException;
+
+    @Path( "updateRoleUsers" )
+    @POST
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * update users assigned to a role
+     * @since 1.5
+     */
+    Boolean updateRoleUsers( Role role )
+        throws RedbackServiceException;
+
+    @Path( "getApplicationRoles/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * @since 1.5
+     */
+    List<ApplicationRoles> getApplicationRoles( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+    @Path( "updateUserRoles" )
+    @POST
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_RBAC_ADMIN_OPERATION )
+    /**
+     * update roles assigned to a user
+     * @since 1.5
+     */
+    Boolean updateUserRoles( User user )
+        throws RedbackServiceException;
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/RoleManagementService.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,257 @@
+package org.codehaus.redback.rest.api.services;
+
+/*
+ * Copyright 2009 The Codehaus.
+ *
+ * Licensed 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.
+ */
+
+import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
+import org.codehaus.redback.integration.security.role.RedbackRoleConstants;
+import org.codehaus.redback.rest.api.model.Operation;
+import org.codehaus.redback.rest.api.model.Permission;
+import org.codehaus.redback.rest.api.model.RegistrationKey;
+import org.codehaus.redback.rest.api.model.User;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.Collection;
+import java.util.List;
+
+@Path( "/userService/" )
+public interface UserService
+{
+    @Path( "getUser/{userName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    User getUser( @PathParam( "userName" ) String username )
+        throws RedbackServiceException;
+
+
+    @Path( "getUsers" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_LIST_OPERATION )
+    List<User> getUsers()
+        throws RedbackServiceException;
+
+    @Path( "createUser" )
+    @POST
+    @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 )
+    Boolean createUser( User user )
+        throws RedbackServiceException;
+
+
+    /**
+     * will create admin user only if not exists !! if exists will return false
+     */
+    @Path( "createAdminUser" )
+    @POST
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( noRestriction = true )
+    Boolean createAdminUser( User user )
+        throws RedbackServiceException;
+
+    @Path( "isAdminUserExists" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true )
+    Boolean isAdminUserExists()
+        throws RedbackServiceException;
+
+
+    @Path( "deleteUser/{userName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION )
+    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 )
+    Boolean updateUser( User user )
+        throws RedbackServiceException;
+
+    @Path( "lockUser/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Boolean lockUser( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+    @Path( "unlockUser/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Boolean unlockUser( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+
+    @Path( "passwordChangeRequired/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Boolean passwordChangeRequired( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+    @Path( "passwordChangeNotRequired/{username}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    /**
+     * @since 1.5
+     */
+    Boolean passwordChangeNotRequired( @PathParam( "username" ) String username )
+        throws RedbackServiceException;
+
+
+    @Path( "updateMe" )
+    @POST
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = false, noPermission = true )
+    /**
+     * 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
+     */
+    Boolean updateMe( User user )
+        throws RedbackServiceException;
+
+    @Path( "ping" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true )
+    Boolean ping()
+        throws RedbackServiceException;
+
+    @Path( "removeFromCache/{userName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    int removeFromCache( @PathParam( "userName" ) String username )
+        throws RedbackServiceException;
+
+    @Path( "getGuestUser" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    User getGuestUser()
+        throws RedbackServiceException;
+
+    @Path( "createGuestUser" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
+    User createGuestUser()
+        throws RedbackServiceException;
+
+    @Path( "registerUser" )
+    @POST
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true, noPermission = true )
+    /**
+     * if redback is not configured for email validation is required, -1 is returned as key
+     * @since 1.4
+     */
+    RegistrationKey registerUser( User user )
+        throws RedbackServiceException;
+
+
+    @Path( "validateKey/{key}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true, noPermission = true )
+    /**
+     * validate the key and the user with forcing a password change for next login.
+     * http session is created.
+     * @param key authentication key
+     * @since 1.4
+     */
+    Boolean validateUserFromKey( @PathParam( "key" ) String key )
+        throws RedbackServiceException;
+
+    @Path( "resetPassword/{user}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true, noPermission = true )
+    /**
+     *
+     * @param user username for send a password reset email
+     * @since 1.4
+     */
+    Boolean resetPassword( @PathParam( "user" ) String user )
+        throws RedbackServiceException;
+
+    @Path( "getUserPermissions/{userName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_LIST_OPERATION )
+    /**
+     * @since 1.4
+     */
+    Collection<Permission> getUserPermissions( @PathParam( "userName" ) String userName )
+        throws RedbackServiceException;
+
+    @Path( "getUserOperations/{userName}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_LIST_OPERATION )
+    /**
+     * @since 1.4
+     */
+    Collection<Operation> getUserOperations( @PathParam( "userName" ) String userName )
+        throws RedbackServiceException;
+
+    @Path( "getCurrentUserPermissions" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true, noPermission = true )
+    /**
+     * return the current logged user permissions, if no logged user guest permissions are returned
+     * @since 1.4
+     */
+    Collection<Permission> getCurrentUserPermissions()
+        throws RedbackServiceException;
+
+    @Path( "getCurrentUserOperations" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true, noPermission = true )
+    /**
+     * return the current logged user operations, if no logged user guest operations are returned
+     * @since 1.4
+     */
+    Collection<Operation> getCurrentUserOperations()
+        throws RedbackServiceException;
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UserService.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,56 @@
+package org.codehaus.redback.rest.api.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.
+ */
+
+import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.Properties;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+@Path( "/utilServices/" )
+public interface UtilServices
+{
+
+    @Path( "getBundleResources" )
+    @GET
+    @Produces( { MediaType.TEXT_PLAIN } )
+    @RedbackAuthorization( noRestriction = true )
+    String getI18nResources( @QueryParam( "locale" ) String locale )
+        throws RedbackServiceException;
+
+    /**
+     * <b>not intended to be exposed as a REST service.</b>
+     * will load i18N resource org/codehaus/plexus/redback/users/messages in default en then in the asked locale.
+     * @param locale
+     * @return
+     * @throws RedbackServiceException
+     */
+    Properties getI18nProperties( String locale )
+        throws RedbackServiceException;
+
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/codehaus/redback/rest/api/services/UtilServices.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,3 @@
+<module>
+  <source path="model" />
+</module>
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/resources/org/codehaus/redback/rest/api/RedbackRestModel.gwt.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml Fri Apr  6 09:58:14 2012
@@ -0,0 +1,235 @@
+<?xml version="1.0"?>
+<!--
+  ~ Copyright 2011 The Codehaus.
+  ~
+  ~ Licensed 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>
+    <artifactId>redback-rest</artifactId>
+    <groupId>org.codehaus.redback</groupId>
+    <version>1.5-SNAPSHOT</version>
+  </parent>
+  <artifactId>redback-rest-services</artifactId>
+  <name>Redback :: REST :: Services</name>
+
+  <properties>
+    <jettyVersion>7.5.3.v20111011</jettyVersion>
+    <tomcatVersion>7.0.21</tomcatVersion>
+    <test.useTomcat>false</test.useTomcat>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-rest-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>jsr250-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-common-integrations</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-users-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-users-cached</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-keys-memory</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-jaxrs</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-xc</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-bundle-jaxrs</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.eclipse.jetty</groupId>
+          <artifactId>jetty-server</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.codehaus.jettison</groupId>
+          <artifactId>jettison</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>javax.ws.rs</groupId>
+      <artifactId>jsr311-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-expression</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-common-test-resources</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-server</artifactId>
+      <version>${jettyVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-plus</artifactId>
+      <version>${jettyVersion}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!--
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-core</artifactId>
+      <version>${tomcatVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-juli</artifactId>
+      <version>${tomcatVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-logging-juli</artifactId>
+      <version>${tomcatVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    -->
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-clean-plugin</artifactId>
+        <configuration>
+          <filesets>
+            <fileset>
+              <directory>${basedir}/${plexus.home}</directory>
+            </fileset>
+          </filesets>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/FakeCreateAdminService**.java</exclude>
+          </excludes>
+          <systemPropertyVariables>
+            <plexus.home>${project.build.directory}/test-home</plexus.home>
+            <derby.system.home>${project.build.directory}/test-home</derby.system.home>
+            <test.useTomcat>${test.useTomcat}</test.useTomcat>
+            <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
+            <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,198 @@
+package org.codehaus.redback.rest.services;
+
+/*
+ * Copyright 2009 The Codehaus.
+ *
+ * Licensed 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.
+ */
+
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.jdo.JdoAuthenticationKey;
+import org.codehaus.plexus.redback.keys.memory.MemoryAuthenticationKey;
+import org.codehaus.plexus.redback.keys.memory.MemoryKeyManager;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
+import org.codehaus.redback.rest.api.model.User;
+import org.codehaus.redback.rest.api.services.LoginService;
+import org.codehaus.redback.rest.api.services.RedbackServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.3
+ */
+@Service( "loginService#rest" )
+public class DefaultLoginService
+    implements LoginService
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    private SecuritySystem securitySystem;
+
+    private HttpAuthenticator httpAuthenticator;
+
+    @Context
+    private HttpServletRequest httpServletRequest;
+
+    @Inject
+    public DefaultLoginService( SecuritySystem securitySystem,
+                                @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator )
+    {
+        this.securitySystem = securitySystem;
+        this.httpAuthenticator = httpAuthenticator;
+    }
+
+
+    public String addAuthenticationKey( String providedKey, String principal, String purpose, int expirationMinutes )
+        throws RedbackServiceException
+    {
+        KeyManager keyManager = securitySystem.getKeyManager();
+        AuthenticationKey key;
+
+        if ( keyManager instanceof MemoryKeyManager )
+        {
+            key = new MemoryAuthenticationKey();
+        }
+        else
+        {
+            key = new JdoAuthenticationKey();
+        }
+
+        key.setKey( providedKey );
+        key.setForPrincipal( principal );
+        key.setPurpose( purpose );
+
+        Calendar now = getNowGMT();
+        key.setDateCreated( now.getTime() );
+
+        if ( expirationMinutes >= 0 )
+        {
+            Calendar expiration = getNowGMT();
+            expiration.add( Calendar.MINUTE, expirationMinutes );
+            key.setDateExpires( expiration.getTime() );
+        }
+
+        keyManager.addKey( key );
+
+        return key.getKey();
+    }
+
+    public Boolean ping()
+        throws RedbackServiceException
+    {
+        return Boolean.TRUE;
+    }
+
+    public Boolean pingWithAutz()
+        throws RedbackServiceException
+    {
+        return Boolean.TRUE;
+    }
+
+    public User logIn( String userName, String password )
+        throws RedbackServiceException
+    {
+        PasswordBasedAuthenticationDataSource authDataSource =
+            new PasswordBasedAuthenticationDataSource( userName, password );
+        try
+        {
+            SecuritySession securitySession = securitySystem.authenticate( authDataSource );
+            if ( securitySession.getAuthenticationResult().isAuthenticated() )
+            {
+                org.codehaus.plexus.redback.users.User user = securitySession.getUser();
+                if ( !user.isValidated() )
+                {
+                    log.info( "user {} not validated", user.getUsername() );
+                    return null;
+                }
+                User restUser = buildRestUser( user );
+
+                // here create an http session
+                httpAuthenticator.authenticate( authDataSource, httpServletRequest.getSession( true ) );
+                return restUser;
+            }
+            return null;
+        }
+        catch ( AuthenticationException e )
+        {
+            throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
+        }
+        catch ( UserNotFoundException e )
+        {
+            throw new RedbackServiceException( e.getMessage() );
+        }
+        catch ( AccountLockedException e )
+        {
+            throw new RedbackServiceException( e.getMessage() );
+        }
+        catch ( MustChangePasswordException e )
+        {
+            return buildRestUser( e.getUser() );
+        }
+    }
+
+    public Boolean isLogged()
+        throws RedbackServiceException
+    {
+        Boolean isLogged = httpAuthenticator.getSecuritySession( httpServletRequest.getSession( true ) ) != null;
+        log.debug( "isLogged {}", isLogged );
+        return isLogged;
+    }
+
+    public Boolean logout()
+        throws RedbackServiceException
+    {
+        HttpSession httpSession = httpServletRequest.getSession();
+        if ( httpSession != null )
+        {
+            httpSession.invalidate();
+        }
+        return Boolean.TRUE;
+    }
+
+    private Calendar getNowGMT()
+    {
+        return Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
+    }
+
+    private User buildRestUser( org.codehaus.plexus.redback.users.User user )
+    {
+        User restUser = new User();
+        restUser.setEmail( user.getEmail() );
+        restUser.setUsername( user.getUsername() );
+        restUser.setPasswordChangeRequired( user.isPasswordChangeRequired() );
+        restUser.setLocked( user.isLocked() );
+        restUser.setValidated( user.isValidated() );
+        restUser.setFullName( user.getFullName() );
+        return restUser;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultLoginService.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,208 @@
+package org.codehaus.redback.rest.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.policy.PasswordEncoder;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolationException;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolations;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
+import org.codehaus.redback.rest.api.model.ErrorMessage;
+import org.codehaus.redback.rest.api.services.PasswordService;
+import org.codehaus.redback.rest.api.services.RedbackServiceException;
+import org.codehaus.redback.rest.services.utils.PasswordValidator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+@Service( "passwordService#rest" )
+public class DefaultPasswordService
+    implements PasswordService
+{
+
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    private SecuritySystem securitySystem;
+
+    private HttpAuthenticator httpAuthenticator;
+
+    private PasswordValidator passwordValidator;
+
+    @Context
+    private HttpServletRequest httpServletRequest;
+
+    @Inject
+    public DefaultPasswordService( SecuritySystem securitySystem,
+                                   @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator,
+                                   PasswordValidator passwordValidator )
+    {
+        this.securitySystem = securitySystem;
+        this.httpAuthenticator = httpAuthenticator;
+        this.passwordValidator = passwordValidator;
+    }
+
+    public org.codehaus.redback.rest.api.model.User changePasswordWithKey( String password, String passwordConfirmation,
+                                                                           String key )
+        throws RedbackServiceException
+    {
+
+
+        //RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
+
+        String principal = null;
+
+        if ( StringUtils.isEmpty( password ) )
+        {
+            throw new RedbackServiceException( "password cannot be empty", Response.Status.FORBIDDEN.getStatusCode() );
+        }
+        if ( StringUtils.isEmpty( passwordConfirmation ) )
+        {
+            throw new RedbackServiceException( "password confirmation cannot be empty",
+                                               Response.Status.FORBIDDEN.getStatusCode() );
+        }
+        if ( !StringUtils.equals( password, passwordConfirmation ) )
+        {
+            throw new RedbackServiceException( "password confirmation must be same as password",
+                                               Response.Status.FORBIDDEN.getStatusCode() );
+        }
+
+        try
+        {
+            AuthenticationKey authKey = securitySystem.getKeyManager().findKey( key );
+
+            principal = authKey.getForPrincipal();
+
+            String encodedPassword = passwordValidator.validatePassword( password, principal );
+
+            User user = securitySystem.getUserManager().findUser( principal );
+            user.setPassword( password );
+            user.setEncodedPassword( encodedPassword );
+            user = securitySystem.getUserManager().updateUser( user );
+
+            return new org.codehaus.redback.rest.api.model.User( user );
+
+        }
+        catch ( KeyManagerException e )
+        {
+            log.info( "issue to find key {}: {}", key, e.getMessage() );
+            throw new RedbackServiceException( "issue with key", Response.Status.FORBIDDEN.getStatusCode() );
+        }
+        catch ( UserNotFoundException e )
+        {
+            log.info( "user {} not found", e.getMessage() );
+            List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>( 2 );
+            ErrorMessage errorMessage = new ErrorMessage( "cannot.update.user.not.found", new String[]{ principal } );
+            errorMessages.add( errorMessage );
+            errorMessage = new ErrorMessage( "admin.deleted.account" );
+            errorMessages.add( errorMessage );
+            throw new RedbackServiceException( errorMessages );
+        }
+        catch ( PasswordRuleViolationException e )
+        {
+            PasswordRuleViolations violations = e.getViolations();
+            List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>( violations.getViolations().size() );
+            if ( violations != null )
+            {
+                for ( String violation : violations.getLocalizedViolations() )
+                {
+                    errorMessages.add( new ErrorMessage( violation ) );
+                }
+            }
+            throw new RedbackServiceException( errorMessages );
+        }
+
+    }
+
+    public org.codehaus.redback.rest.api.model.User changePassword( String userName, String previousPassword,
+                                                                    String password, String passwordConfirmation )
+        throws RedbackServiceException
+    {
+        if ( StringUtils.isEmpty( userName ) )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "username.cannot.be.empty" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+        if ( StringUtils.isEmpty( previousPassword ) )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "password.previous.empty" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+        if ( StringUtils.isEmpty( password ) )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "password.empty" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+        if ( StringUtils.isEmpty( passwordConfirmation ) )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "password.confirmation.empty" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+
+        if ( !StringUtils.equals( password, passwordConfirmation ) )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "password.confirmation.same" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+        try
+        {
+            User u = securitySystem.getUserManager().findUser( userName );
+
+            String previousEncodedPassword = u.getEncodedPassword();
+
+            // check oldPassword with the current one
+
+            PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
+
+            if ( !encoder.isPasswordValid( previousEncodedPassword, previousPassword ) )
+            {
+
+                throw new RedbackServiceException( new ErrorMessage( "password.provided.does.not.match.existing" ),
+                                                   Response.Status.BAD_REQUEST.getStatusCode() );
+            }
+
+            u.setPassword( password );
+
+            u = securitySystem.getUserManager().updateUser( u );
+            return new org.codehaus.redback.rest.api.model.User( u );
+        }
+        catch ( UserNotFoundException e )
+        {
+            throw new RedbackServiceException( new ErrorMessage( "user.not.found" ),
+                                               Response.Status.BAD_REQUEST.getStatusCode() );
+        }
+
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/codehaus/redback/rest/services/DefaultPasswordService.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision