use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ddf by codice.
the class OidcRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
// token is guaranteed to be of type OidcAuthenticationToken by the supports() method
OidcAuthenticationToken oidcAuthenticationToken = (OidcAuthenticationToken) authenticationToken;
OidcCredentials credentials = (OidcCredentials) oidcAuthenticationToken.getCredentials();
OidcConfiguration oidcConfiguration = oidcHandlerConfiguration.getOidcConfiguration();
OIDCProviderMetadata oidcProviderMetadata = oidcConfiguration.findProviderMetadata();
WebContext webContext = (WebContext) oidcAuthenticationToken.getContext();
OidcClient<OidcConfiguration> oidcClient = oidcHandlerConfiguration.getOidcClient(webContext.getFullRequestURL());
int connectTimeout = oidcHandlerConfiguration.getConnectTimeout();
int readTimeout = oidcHandlerConfiguration.getReadTimeout();
try {
OidcCredentialsResolver oidcCredentialsResolver = new OidcCredentialsResolver(oidcConfiguration, oidcClient, oidcProviderMetadata, connectTimeout, readTimeout);
oidcCredentialsResolver.resolveIdToken(credentials, webContext);
} catch (TechnicalException e) {
throw new AuthenticationException(e);
}
// problem getting id token, invalidate credentials
if (credentials.getIdToken() == null) {
webContext.getSessionStore().destroySession(webContext);
String msg = String.format("Could not fetch id token with Oidc credentials (%s). " + "This may be due to the credentials expiring. " + "Invalidating session in order to acquire valid credentials.", credentials);
LOGGER.warn(msg);
throw new AuthenticationException(msg);
}
OidcProfileCreator oidcProfileCreator = new CustomOidcProfileCreator(oidcConfiguration, oidcClient);
Optional<UserProfile> userProfile = oidcProfileCreator.create(credentials, webContext);
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
simpleAuthenticationInfo.setCredentials(credentials);
if (userProfile.isPresent()) {
OidcProfile oidcProfile = (OidcProfile) userProfile.get();
simpleAuthenticationInfo.setPrincipals(createPrincipalCollectionFromCredentials(oidcProfile));
} else {
simpleAuthenticationInfo.setPrincipals(new SimplePrincipalCollection());
}
return simpleAuthenticationInfo;
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ddf by codice.
the class SamlRealm method doGetAuthenticationInfo.
/**
* Perform authentication based on the supplied token.
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
Object credential = null;
// perform validation
if (token instanceof SAMLAuthenticationToken) {
try {
samlAssertionValidator.validate((SAMLAuthenticationToken) token);
credential = token.getCredentials();
} catch (AuthenticationFailureException e) {
String msg = "Unable to validate request's authentication.";
LOGGER.info(msg);
throw new AuthenticationException(msg, e);
}
}
if (credential == null) {
String msg = "Unable to authenticate credential. A NULL credential was provided in the supplied authentication token. This may be due to an error with the SSO server that created the token.";
LOGGER.info(msg);
throw new AuthenticationException(msg);
}
LOGGER.debug("Received credentials.");
LOGGER.debug("Creating token authentication information with SAML.");
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
Element securityToken = checkForSecurityToken(credential);
SimplePrincipalCollection principals = createPrincipalFromToken(securityToken);
simpleAuthenticationInfo.setPrincipals(principals);
simpleAuthenticationInfo.setCredentials(credential);
return simpleAuthenticationInfo;
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ddf by codice.
the class UsernamePasswordRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String credentials = (String) token.getCredentials();
String[] userpass = credentials.split(":");
if (userpass.length != 2) {
throw new AuthenticationException("Credentials were not in the correct format.");
}
String user = new String(Base64.getDecoder().decode(userpass[0]), StandardCharsets.UTF_8);
String pass = new String(Base64.getDecoder().decode(userpass[1]), StandardCharsets.UTF_8);
Subject subject = null;
for (JaasRealm jaasRealm : realmList) {
try {
subject = login(user, pass, jaasRealm.getName());
LOGGER.trace("Login succeeded for {} against realm {}", user, jaasRealm.getName());
break;
} catch (LoginException e) {
LOGGER.trace("Login failed for {} against realm {}", user, jaasRealm.getName());
}
}
if (subject != null) {
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
SimplePrincipalCollection principalCollection = createPrincipalCollectionFromSubject(subject);
simpleAuthenticationInfo.setPrincipals(principalCollection);
simpleAuthenticationInfo.setCredentials(credentials);
return simpleAuthenticationInfo;
}
throw new AuthenticationException("Login failed for user: " + user);
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project ddf by codice.
the class AbstractStsRealm method doGetAuthenticationInfo.
/**
* Perform authentication based on the supplied token.
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
String method = "doGetAuthenticationInfo( AuthenticationToken token )";
Object credential;
if (token instanceof SAMLAuthenticationToken) {
credential = token.getCredentials();
} else if (token instanceof BaseAuthenticationToken) {
credential = ((BaseAuthenticationToken) token).getCredentialsAsXMLString();
} else {
credential = token.getCredentials().toString();
}
if (credential == null) {
String msg = "Unable to authenticate credential. A NULL credential was provided in the supplied authentication token. This may be due to an error with the SSO server that created the token.";
LOGGER.info(msg);
throw new AuthenticationException(msg);
} else {
//removed the credentials from the log message for now, I don't think we should be dumping user/pass into log
LOGGER.debug("Received credentials.");
}
SecurityToken securityToken;
if (token instanceof SAMLAuthenticationToken && credential instanceof SecurityToken) {
securityToken = renewSecurityToken((SecurityToken) credential);
} else {
securityToken = requestSecurityToken(credential);
}
LOGGER.debug("Creating token authentication information with SAML.");
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityAssertion assertion = new SecurityAssertionImpl(securityToken);
principals.add(assertion.getPrincipal(), NAME);
principals.add(assertion, NAME);
simpleAuthenticationInfo.setPrincipals(principals);
simpleAuthenticationInfo.setCredentials(credential);
return simpleAuthenticationInfo;
}
use of org.apache.shiro.authc.SimpleAuthenticationInfo in project bamboobsc by billchen198318.
the class GreenStepBaseAuthorizingRealm method doGetAuthenticationInfo.
/**
* 認證
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
GreenStepBaseUsernamePasswordToken token = (GreenStepBaseUsernamePasswordToken) authenticationToken;
String account = token.getUsername();
AccountVO accountObj = new AccountVO();
accountObj.setAccount(account);
try {
DefaultResult<AccountVO> result = accountService.findByUK(accountObj);
if (result.getValue() == null) {
return null;
}
accountObj = result.getValue();
return new SimpleAuthenticationInfo(accountObj.getAccount(), accountObj.getPassword(), this.getName());
} catch (ServiceException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations