org.apache.shiro.authc.SimpleAccount Java Examples

The following examples show how to use org.apache.shiro.authc.SimpleAccount. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FirstSuccessfulModularRealAuthenticatorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSingleRealmFailureIsStillSuccessful() {
  UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken("username", "password");

  Realm realmOne = mock(Realm.class);
  Realm realmTwo = mock(Realm.class);

  when(realmOne.supports(usernamePasswordToken)).thenReturn(true);
  when(realmTwo.supports(usernamePasswordToken)).thenReturn(true);

  when(realmOne.getAuthenticationInfo(usernamePasswordToken)).thenThrow(new IncorrectCredentialsException());
  when(realmTwo.getAuthenticationInfo(usernamePasswordToken)).thenReturn(new SimpleAccount());

  firstSuccessfulModularRealmAuthenticator
      .doMultiRealmAuthentication(Lists.newArrayList(realmOne, realmTwo), usernamePasswordToken);
}
 
Example #2
Source File: KnoxJwtRealm.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
  JWTAuthenticationToken upToken = (JWTAuthenticationToken) token;

  if (validateToken(upToken.getToken())) {
    try {
      SimpleAccount account = new SimpleAccount(getName(upToken), upToken.getToken(), getName());
      account.addRole(mapGroupPrincipals(getName(upToken)));
      return account;
    } catch (ParseException e) {
      LOGGER.error("ParseException in doGetAuthenticationInfo", e);
    }
  }
  return null;
}
 
Example #3
Source File: KerberosRealm.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
/**
 * This is called when Kerberos authentication is done and a {@link KerberosToken} has
 * been acquired.
 * This function returns a Shiro {@link SimpleAccount} based on the {@link KerberosToken}
 * provided. Null otherwise.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
    org.apache.shiro.authc.AuthenticationToken authenticationToken)
    throws org.apache.shiro.authc.AuthenticationException {
  if (null != authenticationToken) {
    KerberosToken kerberosToken = (KerberosToken) authenticationToken;
    SimpleAccount account = new SimpleAccount(kerberosToken.getPrincipal(),
        kerberosToken.getCredentials(), kerberosToken.getClass().getName());
    account.addRole(mapGroupPrincipals((String)kerberosToken.getPrincipal()));
    return account;
  }
  return null;
}
 
Example #4
Source File: FormRealm.java    From shiro-jwt with MIT License 5 votes vote down vote up
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    UserDefault user = userRepository.findByUserId(upToken.getUsername());
    if (user != null) {
        SimpleAccount account = new SimpleAccount(user, user.getCredentials(), getName());
        account.addRole(user.getRoles());
        return account;
    }

    return null;
}
 
Example #5
Source File: JWTRealm.java    From shiro-jwt with MIT License 5 votes vote down vote up
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
    JWTAuthenticationToken upToken = (JWTAuthenticationToken) token;
    UserDefault user = userRepository.findById(upToken.getUserId());

    if (user != null && userRepository.validateToken(upToken.getToken())) {
        SimpleAccount account = new SimpleAccount(user, upToken.getToken(), getName());
        account.addRole(user.getRoles());
        return account;
    }

    return null;
}
 
Example #6
Source File: TestIniRealm.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
@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);
}