List of usage examples for org.apache.shiro.authc SimpleAccount setPrincipals
public void setPrincipals(PrincipalCollection principals)
From source file:at.pollux.thymeleaf.shiro.dialect.test.TestIniRealm.java
License:Apache License
@Override protected void add(SimpleAccount account) { String username = (String) account.getPrincipals().getPrimaryPrincipal(); // Let's add some additional principals for testing SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(); principalCollection.addAll(account.getPrincipals()); principalCollection.add(counter.getAndIncrement(), "integerRealm"); TestObjPrincipal objPrinc = new TestObjPrincipal(username.toUpperCase() + " " + username.toUpperCase()); principalCollection.add(objPrinc, "objRealm"); account.setPrincipals(principalCollection); super.add(account); }
From source file:org.zunpeng.thymeleaf.shiro.dialect.test.TestIniRealm.java
License:Apache License
@Override protected void add(SimpleAccount account) { String username = (String) account.getPrincipals().getPrimaryPrincipal(); // Let's add some additional principals for testing SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(); principalCollection.addAll(account.getPrincipals()); principalCollection.add(counter.getAndIncrement(), "integerRealm"); TestObjPrincipal objPrinc = new TestObjPrincipal(username.toUpperCase() + " " + username.toUpperCase()); principalCollection.add(objPrinc, "objRealm"); account.setPrincipals(principalCollection); super.add(account); //To change body of generated methods, choose Tools | Templates. }
From source file:streamflow.server.security.DatastoreRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { // Make sure the token is of the property type if (!(token instanceof UsernamePasswordToken)) { //LOG.error("The provided token is not a UsernamePasswordToken"); throw new AuthenticationException("The provided token is not a UsernamePasswordToken"); }//from w ww . ja v a 2 s . c o m // Retrieve the username from the token UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token; String username = usernamePasswordToken.getUsername(); if (username == null) { //LOG.error("The provided token does not contain a username"); throw new AuthenticationException("The provided token does not contain a username"); } User user = getUserByUsernameOrEmail(username); if (user == null) { LOG.warn("User with the specified username does not exist: " + username); throw new AuthenticationException("The username/password was invalid"); } // Make sure the user account is enabled if (!user.getEnabled()) { //LOG.error("User account with the specified username is disabled: {}", username); throw new AuthenticationException("The user account is disabled"); } // Generate the authentication info using the passsword and salt SimpleAccount info = new SimpleAccount(username, user.getPassword(), new SimpleByteSource(user.getPasswordSalt()), getName()); // Associate the principals with the authentication info SimplePrincipalCollection principals = new SimplePrincipalCollection(); principals.add(user.getId(), getName()); principals.add(user.getUsername(), getName()); principals.add(user.getEmail(), getName()); info.setPrincipals(principals); return info; }