Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
JBoss, Home of Professional Open Source Copyright Red Hat, Inc., and individual contributors by the

Authors:
tag. See the copyright.txt in the distribution for a full listing of individual contributors. 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.
 
 
 package org.jboss.aerogear.security.picketlink.authz;
 
 
 
 import  javax.enterprise.context.ApplicationScoped;
 import  javax.inject.Inject;
 import java.util.List;

IdentityManagement allows to assign a set of roles to org.jboss.aerogear.security.model.AeroGearUser on Identity Manager provider
 
 @ApplicationScoped
 public class IdentityManagementImpl implements IdentityManagement {
 
     @Inject
     private IdentityManager identityManager;
 
     @Inject
 
     @Inject
     private Identity identity;

    
This method allows to specify which roles must be assigned to org.jboss.aerogear.security.model.AeroGearUser

Parameters:
roles The list of roles.
Returns:
GrantMethods is a builder which a allows to apply a list of roles to the specified org.jboss.aerogear.security.model.AeroGearUser.
 
     @Override
     public GrantMethods grant(String... roles) {
         return .roles(roles);
     }
 
     @Override
     public AeroGearUser get(String idthrows RuntimeException {
         User user = .getUser(id);
         if (user == null) {
             throw new RuntimeException("User do not exist");
         }
         return Converter.convertToAerogearUser(.getUser(id));
     }
 
     @Override
     public void remove(AeroGearUser aeroGearUser) {
 
         if (isLoggedIn(aeroGearUser)) {
             throw new RuntimeException("User is logged in");
         }
         .remove(.getUser(aeroGearUser.getUsername()));
     }
 
     @Override
     public List<AeroGearUserfindAllByRole(String roleName) {
         Role role = .getRole(roleName);
         List aerogearUsers = new ArrayList();
         IdentityQuery<Userquery = .createIdentityQuery(User.class);
         query.setParameter(.role);
         List<Userresult = query.getResultList();
         for (User user : result) {
             aerogearUsers.add(Converter.convertToAerogearUser(user));
         }
         return aerogearUsers;
     }

    
This method creates a new AeroGearUser

Parameters:
aeroGearUser
    @Override
    public void create(AeroGearUser aeroGearUser) {
        User picketLinkUser = new SimpleUser(aeroGearUser.getUsername());
        picketLinkUser.setEmail(aeroGearUser.getEmail());
        picketLinkUser.setFirstName(aeroGearUser.getFirstName());
        picketLinkUser.setLastName(aeroGearUser.getLastName());
        .add(picketLinkUser);
        /*
         * Disclaimer: PlainTextPassword will encode passwords in SHA-512 with SecureRandom-1024 salt
         * See http://lists.jboss.org/pipermail/security-dev/2013-January/000650.html for more information
         */
        .updateCredential(picketLinkUsernew Password(aeroGearUser.getPassword()));
    }
    private boolean isLoggedIn(AeroGearUser aeroGearUser) {
        return .isLoggedIn() && .getUser().getLoginName().equals(aeroGearUser.getUsername());
    }
New to GrepCode? Check out our FAQ X