use of org.apache.cxf.common.security.UsernameToken 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.cxf.common.security.UsernameToken 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()));
}
}
use of org.apache.cxf.common.security.UsernameToken in project cxf by apache.
the class AbstractUsernameTokenAuthenticatingInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage msg) throws Fault {
SecurityToken token = msg.get(SecurityToken.class);
SecurityContext context = msg.get(SecurityContext.class);
if (token == null || context == null || context.getUserPrincipal() == null) {
super.handleMessage(msg);
return;
}
UsernameToken ut = (UsernameToken) token;
Subject subject = createSubject(ut.getName(), ut.getPassword(), ut.isHashed(), ut.getNonce(), ut.getCreatedTime());
SecurityContext sc = doCreateSecurityContext(context.getUserPrincipal(), subject);
msg.put(SecurityContext.class, sc);
}
use of org.apache.cxf.common.security.UsernameToken in project cxf by apache.
the class JAASLoginInterceptorTest method addUsernameToken.
private void addUsernameToken(Message message, String username, String password) {
UsernameToken token = new UsernameToken(username, password, "", false, null, "");
message.put(SecurityToken.class, token);
}
use of org.apache.cxf.common.security.UsernameToken in project cxf by apache.
the class CallbackHandlerProviderUsernameToken method create.
@Override
public CallbackHandler create(Message message) {
SecurityToken token = message.get(SecurityToken.class);
if (!(token instanceof UsernameToken)) {
return null;
}
UsernameToken ut = (UsernameToken) token;
if (ut.getPasswordType().endsWith("PasswordDigest")) {
return new NameDigestPasswordCallbackHandler(ut.getName(), ut.getPassword(), ut.getNonce(), ut.getCreatedTime());
}
return new NamePasswordCallbackHandler(ut.getName(), ut.getPassword());
}
Aggregations