use of org.apache.wss4j.common.principal.UsernameTokenPrincipal in project ddf by codice.
the class AuthNStatementProvider method getStatement.
/*
* (non-Javadoc)
*
* @see
* org.apache.cxf.sts.token.provider.AuthenticationStatementProvider#getStatement(org.apache
* .cxf.sts.token.provider.TokenProviderParameters)
*/
@Override
public AuthenticationStatementBean getStatement(TokenProviderParameters providerParameters) {
AuthenticationStatementBean authBean = new AuthenticationStatementBean();
authBean.setSessionIndex(Integer.toString(secureRandom.nextInt()));
TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
ReceivedToken receivedToken = null;
if (tokenRequirements.getValidateTarget() != null) {
receivedToken = tokenRequirements.getValidateTarget();
} else if (tokenRequirements.getOnBehalfOf() != null) {
receivedToken = tokenRequirements.getOnBehalfOf();
} else if (tokenRequirements.getActAs() != null) {
receivedToken = tokenRequirements.getActAs();
} else if (tokenRequirements.getRenewTarget() != null) {
receivedToken = tokenRequirements.getRenewTarget();
}
if (receivedToken != null) {
Principal principal = receivedToken.getPrincipal();
if (principal instanceof UsernameTokenPrincipal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT);
} else if (principal instanceof X500Principal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509);
} else if (principal instanceof KerberosPrincipal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_KERBEROS);
} else {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED);
}
} else {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED);
}
return authBean;
}
use of org.apache.wss4j.common.principal.UsernameTokenPrincipal in project jbossws-cxf by jbossws.
the class AuthenticationMgrSubjectCreatingInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
JBossAuthenticationManager authenticationManger = message.get(JBossAuthenticationManager.class);
if (authenticationManger == null) {
return;
}
SecurityContext context = message.get(SecurityContext.class);
if (context == null || context.getUserPrincipal() == null) {
Loggers.SECURITY_LOGGER.userPrincipalNotAvailableOnCurrentMessage();
return;
}
SecurityToken token = message.get(SecurityToken.class);
Subject subject = null;
if (token != null) {
// Try authenticating using SecurityToken info
if (token.getTokenType() != TokenType.UsernameToken) {
throw Messages.MESSAGES.unsupportedTokenType(token.getTokenType());
}
UsernameToken ut = (UsernameToken) token;
subject = helper.createSubject(authenticationManger, ut.getName(), ut.getPassword(), ut.isHashed(), ut.getNonce(), ut.getCreatedTime());
} else {
// Try authenticating using WSS4J internal info (previously set into SecurityContext by WSS4JInInterceptor)
Principal p = context.getUserPrincipal();
if (!(p instanceof UsernameTokenPrincipal)) {
throw Messages.MESSAGES.couldNotGetSubjectInfo();
}
UsernameTokenPrincipal up = (UsernameTokenPrincipal) p;
subject = helper.createSubject(authenticationManger, up.getName(), up.getPassword(), up.isPasswordDigest(), up.getNonce(), up.getCreatedTime());
}
Principal principal = getPrincipal(context.getUserPrincipal(), subject);
message.put(SecurityContext.class, createSecurityContext(principal, subject));
}
use of org.apache.wss4j.common.principal.UsernameTokenPrincipal in project cxf by apache.
the class WSS4JInOutTest method testEncryptedUsernameToken.
@Test
public void testEncryptedUsernameToken() throws Exception {
Map<String, Object> outProperties = new HashMap<>();
outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION);
outProperties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
outProperties.put(ConfigurationConstants.USER, "alice");
outProperties.put("password", "alicePassword");
outProperties.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
outProperties.put(ConfigurationConstants.ENCRYPTION_PARTS, "{Content}{" + WSS4JConstants.WSSE_NS + "}UsernameToken");
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION);
inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
List<String> xpaths = new ArrayList<>();
xpaths.add("//wsse:Security");
SoapMessage inmsg = makeInvocation(outProperties, xpaths, inProperties);
List<WSHandlerResult> handlerResults = getResults(inmsg);
assertNotNull(handlerResults);
assertSame(handlerResults.size(), 1);
//
// This should contain exactly 2 protection results
//
final java.util.List<WSSecurityEngineResult> protectionResults = handlerResults.get(0).getResults();
assertNotNull(protectionResults);
assertSame(protectionResults.size(), 2);
final Principal p1 = (Principal) protectionResults.get(0).get(WSSecurityEngineResult.TAG_PRINCIPAL);
final Principal p2 = (Principal) protectionResults.get(1).get(WSSecurityEngineResult.TAG_PRINCIPAL);
assertTrue(p1 instanceof UsernameTokenPrincipal || p2 instanceof UsernameTokenPrincipal);
Principal utPrincipal = p1 instanceof UsernameTokenPrincipal ? p1 : p2;
SecurityContext securityContext = inmsg.get(SecurityContext.class);
assertNotNull(securityContext);
assertSame(securityContext.getUserPrincipal(), utPrincipal);
}
use of org.apache.wss4j.common.principal.UsernameTokenPrincipal in project jbossws-cxf by jbossws.
the class SubjectCreatingPolicyInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
Endpoint ep = message.getExchange().get(Endpoint.class);
SecurityDomainContext sdc = ep.getSecurityDomainContext();
SecurityContext context = message.get(SecurityContext.class);
if (context == null || context.getUserPrincipal() == null) {
Loggers.SECURITY_LOGGER.userPrincipalNotAvailableOnCurrentMessage();
return;
}
SecurityToken token = message.get(SecurityToken.class);
Subject subject = null;
if (token != null) {
// Try authenticating using SecurityToken info
if (token.getTokenType() != TokenType.UsernameToken) {
throw Messages.MESSAGES.unsupportedTokenType(token.getTokenType());
}
UsernameToken ut = (UsernameToken) token;
subject = createSubject(sdc, ut.getName(), ut.getPassword(), ut.isHashed(), ut.getNonce(), ut.getCreatedTime());
} else {
// Try authenticating using WSS4J internal info (previously set into SecurityContext by WSS4JInInterceptor)
Principal p = context.getUserPrincipal();
if (!(p instanceof UsernameTokenPrincipal)) {
throw Messages.MESSAGES.couldNotGetSubjectInfo();
}
UsernameTokenPrincipal up = (UsernameTokenPrincipal) p;
subject = createSubject(sdc, up.getName(), up.getPassword(), up.isPasswordDigest(), up.getNonce(), up.getCreatedTime());
}
Principal principal = getPrincipal(context.getUserPrincipal(), subject);
message.put(SecurityContext.class, createSecurityContext(principal, subject));
}
use of org.apache.wss4j.common.principal.UsernameTokenPrincipal in project cxf by apache.
the class WSS4JTokenConverter method convertToken.
public static void convertToken(Message msg, Principal p) {
if (p instanceof UsernameTokenPrincipal) {
UsernameTokenPrincipal utp = (UsernameTokenPrincipal) p;
String nonce = null;
if (utp.getNonce() != null) {
nonce = Base64Utility.encode(utp.getNonce());
}
msg.put(org.apache.cxf.common.security.SecurityToken.class, new UsernameToken(utp.getName(), utp.getPassword(), utp.getPasswordType(), utp.isPasswordDigest(), nonce, utp.getCreatedTime()));
}
}
Aggregations