List of usage examples for org.apache.shiro.authc.pam UnsupportedTokenException UnsupportedTokenException
public UnsupportedTokenException(Throwable cause)
From source file:biz.neustar.nexus.plugins.gitlab.GitlabAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not supported. A " + UsernamePasswordToken.class.getName() + " is required."); }// w w w.j a v a2 s . c o m UsernamePasswordToken userPass = (UsernamePasswordToken) authenticationToken; String token = new String(userPass.getPassword()); String username = userPass.getUsername(); if (token.isEmpty()) { LOGGER.debug(GITLAB_MSG + "token for {} is empty", username); return null; } try { LOGGER.debug(GITLAB_MSG + "authenticating {}", username); LOGGER.debug(GITLAB_MSG + "null? " + (gitlab == null)); LOGGER.debug(GITLAB_MSG + "null? " + (gitlab.getRestClient() == null)); GitlabUser gitlabUser = gitlab.getRestClient().getUser(username, token); User user = gitlabUser.toUser(); if (user.getStatus() != UserStatus.active) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", user); throw new AuthenticationException(DISABLED_USER_MESSAGE + " for " + username); } if (user.getUserId() == null || user.getUserId().isEmpty()) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", user); throw new AuthenticationException(DEFAULT_MESSAGE + " for " + username); } LOGGER.debug(GITLAB_MSG + "successfully authenticated {}", username); return new SimpleAuthenticationInfo(gitlabUser, userPass.getCredentials(), getName()); } catch (Exception e) { LOGGER.debug(GITLAB_MSG + "authentication failed {}", username); throw new AuthenticationException(DEFAULT_MESSAGE, e); } }
From source file:com.manydesigns.portofino.shiro.GAEPortofinoRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) { if (!(token instanceof ServletContainerToken)) { throw new UnsupportedTokenException("Token not supported: " + token); }/*ww w .j a v a2s.c om*/ //On GAE, if the user was logged by the container, it is also known to the UserService UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user == null) { throw new UnknownAccountException( "User is authenticated to the container, but is not known to the UserService"); } //TODO verifica utilizzo User come principal direttamente return new SimpleAuthenticationInfo(user, token.getCredentials(), getName()); }
From source file:com.pingunaut.nexus3.crowd.plugin.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException( String.format("Token of type %s is not supported. A %s is required.", token.getClass().getName(), UsernamePasswordToken.class.getName())); }/* w w w.j a va2 s . co m*/ UsernamePasswordToken t = (UsernamePasswordToken) token; LOGGER.info("doGetAuthenticationInfo for " + t.getUsername()); boolean authenticated = client.authenticate(t); LOGGER.info("crowd authenticated: " + authenticated); if (authenticated) { return createSimpleAuthInfo(t); } else { return null; } }
From source file:eu.eubrazilcc.lvl.storage.security.shiro.LinkedInRealm.java
License:EUPL
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { // validate token if (token == null) { throw new CredentialsException("Uninitialized token"); }// w w w . j a v a 2 s .com if (!(token instanceof AccessTokenToken)) { throw new UnsupportedTokenException("Unsuported token type: " + token.getClass().getCanonicalName()); } // get access token final AccessTokenToken accessToken = (AccessTokenToken) token; final String secret = trimToNull(accessToken.getToken()); if (isEmpty(secret)) { throw new AccountException("Empty tokens are not allowed in this realm"); } // find token in the LVL OAuth2 database String ownerid = null; final AtomicReference<String> ownerIdRef = new AtomicReference<String>(); if (TOKEN_DAO.isValid(secret, ownerIdRef)) { ownerid = ownerIdRef.get(); } if (isEmpty(ownerid)) { throw new IncorrectCredentialsException("Incorrect credentials found"); } // find resource owner in the LVL IdP database final ResourceOwner owner = RESOURCE_OWNER_DAO.useGravatar(false).find(ownerid); if (owner == null || owner.getUser() == null) { throw new UnknownAccountException("No account found for user [" + ownerid + "]"); } return new SimpleAuthenticationInfo(ownerid, secret, getName()); }
From source file:eu.eubrazilcc.lvl.storage.security.shiro.LvlBasicRealm.java
License:EUPL
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { // validate token if (token == null) { throw new CredentialsException("Uninitialized token"); }//from w w w . j a v a 2 s . c o m if (!(token instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Unsuported token type: " + token.getClass().getCanonicalName()); } // get user name final UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token; final String username = trimToNull(usernamePasswordToken.getUsername()); if (isEmpty(username)) { throw new AccountException("Empty usernames are not allowed in this realm"); } // find resource owner in the LVL IdP database final String ownerid = toResourceOwnerId(LVL_IDENTITY_PROVIDER, username); final ResourceOwner owner = RESOURCE_OWNER_DAO.useGravatar(false).find(ownerid); if (owner == null || owner.getUser() == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } return new SimpleAuthenticationInfo(ownerid, owner.getUser().getPassword().toCharArray(), decodeHex(owner.getUser().getSalt()), getName()); }
From source file:org.seedstack.seed.security.internal.realms.ShiroRealmAdapter.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { org.seedstack.seed.security.api.AuthenticationToken seedToken = convertToken(token); if (seedToken == null) { throw new UnsupportedTokenException("The token " + token.getClass() + " is not supported"); }//from w w w . j ava 2 s . c o m org.seedstack.seed.security.api.AuthenticationInfo apiAuthenticationInfo; try { apiAuthenticationInfo = realm.getAuthenticationInfo(seedToken); } catch (org.seedstack.seed.security.api.exceptions.IncorrectCredentialsException e) { throw new IncorrectCredentialsException(e); } catch (org.seedstack.seed.security.api.exceptions.UnknownAccountException e) { throw new UnknownAccountException(e); } catch (org.seedstack.seed.security.api.exceptions.UnsupportedTokenException e) { throw new UnsupportedTokenException(e); } catch (org.seedstack.seed.security.api.exceptions.AuthenticationException e) { throw new AuthenticationException(e); } SimpleAuthenticationInfo authcInfo = new SimpleAuthenticationInfo(); SimplePrincipalCollection principals = new SimplePrincipalCollection( apiAuthenticationInfo.getIdentityPrincipal(), this.getName()); authcInfo.setCredentials(token.getCredentials()); //Realm principals for (PrincipalProvider<?> principal : apiAuthenticationInfo.getOtherPrincipals()) { principals.add(principal, this.getName()); } //Custom principals for (PrincipalCustomizer<?> principalCustomizer : principalCustomizers) { if (principalCustomizer.supportedRealm().isAssignableFrom(getRealm().getClass())) { for (PrincipalProvider<?> principal : principalCustomizer.principalsToAdd( apiAuthenticationInfo.getIdentityPrincipal(), apiAuthenticationInfo.getOtherPrincipals())) { principals.add(principal, this.getName()); } } } authcInfo.setPrincipals(principals); return authcInfo; }
From source file:org.seedstack.seed.security.internal.ShiroRealmAdapter.java
License:Mozilla Public License
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { org.seedstack.seed.security.AuthenticationToken seedToken = convertToken(token); if (seedToken == null) { throw new UnsupportedTokenException("The token " + token.getClass() + " is not supported"); }/*from w ww. j av a 2 s .c o m*/ org.seedstack.seed.security.AuthenticationInfo apiAuthenticationInfo; try { apiAuthenticationInfo = realm.getAuthenticationInfo(seedToken); } catch (org.seedstack.seed.security.IncorrectCredentialsException e) { throw new IncorrectCredentialsException(e); } catch (org.seedstack.seed.security.UnknownAccountException e) { throw new UnknownAccountException(e); } catch (org.seedstack.seed.security.UnsupportedTokenException e) { throw new UnsupportedTokenException(e); } catch (org.seedstack.seed.security.AuthenticationException e) { throw new AuthenticationException(e); } SimpleAuthenticationInfo authcInfo = new SimpleAuthenticationInfo(); SimplePrincipalCollection principals = new SimplePrincipalCollection( apiAuthenticationInfo.getIdentityPrincipal(), this.getName()); authcInfo.setCredentials(token.getCredentials()); //Realm principals for (PrincipalProvider<?> principal : apiAuthenticationInfo.getOtherPrincipals()) { principals.add(principal, this.getName()); } //Custom principals for (PrincipalCustomizer<?> principalCustomizer : principalCustomizers) { if (principalCustomizer.supportedRealm().isAssignableFrom(getRealm().getClass())) { for (PrincipalProvider<?> principal : principalCustomizer.principalsToAdd( apiAuthenticationInfo.getIdentityPrincipal(), apiAuthenticationInfo.getOtherPrincipals())) { principals.add(principal, this.getName()); } } } authcInfo.setPrincipals(principals); return authcInfo; }
From source file:org.sonatype.nexus.jsecurity.realms.external.crowd.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not " + "supported. A " + UsernamePasswordToken.class.getName() + " is required."); }//from ww w.j a v a 2 s . c o m UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String password = new String(token.getPassword()); try { crowdClientHolder.getAuthenticationManager().authenticate(token.getUsername(), password); return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } catch (RemoteException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } catch (InactiveAccountException e) { throw new DisabledAccountException(e); } catch (ExpiredCredentialException e) { throw new IncorrectCredentialsException(e); } catch (InvalidAuthenticationException e) { throw new IncorrectCredentialsException(e); } catch (InvalidAuthorizationTokenException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } catch (ApplicationAccessDeniedException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } }
From source file:org.sonatype.nexus.plugins.crowd.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not supported. A " + UsernamePasswordToken.class.getName() + " is required."); }/*ww w .ja v a2 s . c om*/ UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String password = new String(token.getPassword()); try { crowdClientHolder.getAuthenticationManager().authenticate(token.getUsername(), password); return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } catch (RemoteException e) { throw new AuthenticationException(DEFAULT_MESSAGE, e); } }
From source file:org.sonatype.nexus.plugins.crowd.security.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not supported. A " + UsernamePasswordToken.class.getName() + " is required."); }//from w w w .j a v a 2 s .co m UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String password = new String(token.getPassword()); try { restClient.authenticate(token.getUsername(), password); return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } catch (RemoteException re) { throw new AccountException("Invalid login credentials for user '" + token.getUsername() + "'"); } }