use of org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl in project ddf by codice.
the class UPBSTValidator method createPrincipal.
/**
* Create a principal based on the authenticated UsernameToken.
*/
private Principal createPrincipal(String username, String passwordValue, String passwordType, String nonce, String createdTime) {
boolean hashed = false;
if (WSConstants.PASSWORD_DIGEST.equals(passwordType)) {
hashed = true;
}
WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(username, hashed);
if (nonce != null) {
principal.setNonce(nonce.getBytes(StandardCharsets.UTF_8));
}
principal.setPassword(passwordValue);
principal.setCreatedTime(createdTime);
principal.setPasswordType(passwordType);
return principal;
}
use of org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl in project testcases by coheigea.
the class SyncopeBasicAuthInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
String name = null;
if (policy != null) {
name = policy.getUserName();
}
String error = "No user credentials are available";
LOG.warning(error + " " + "for name: " + name);
throw new SecurityException(error);
}
try {
UsernameToken token = convertPolicyToToken(policy);
Credential credential = new Credential();
credential.setUsernametoken(token);
RequestData data = new RequestData();
data.setMsgContext(message);
credential = validator.validate(credential, data);
// Create a Principal/SecurityContext
Principal p = null;
if (credential != null && credential.getPrincipal() != null) {
p = credential.getPrincipal();
} else {
p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
((WSUsernameTokenPrincipalImpl) p).setPassword(policy.getPassword());
}
message.put(SecurityContext.class, createSecurityContext(p));
} catch (Exception ex) {
throw new Fault(ex);
}
}
use of org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl in project cxf by apache.
the class CustomUTValidator method validate.
public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
Credential cred = super.validate(credential, data);
UsernameToken ut = credential.getUsernametoken();
WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(ut.getName(), ut.isHashed());
principal.setCreatedTime(ut.getCreated());
principal.setNonce(principal.getNonce());
principal.setPassword(ut.getPassword());
principal.setPasswordType(ut.getPasswordType());
Subject subject = new Subject();
subject.getPrincipals().add(principal);
if ("Alice".equals(ut.getName())) {
subject.getPrincipals().add(new SimpleGroup("manager", ut.getName()));
}
subject.getPrincipals().add(new SimpleGroup("worker", ut.getName()));
cred.setSubject(subject);
return cred;
}
use of org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl in project ddf by codice.
the class UsernameTokenValidator method createPrincipal.
/**
* Create a principal based on the authenticated UsernameToken.
*/
private Principal createPrincipal(String username, String passwordValue, String passwordType, String nonce, String createdTime) {
boolean hashed = false;
if (WSConstants.PASSWORD_DIGEST.equals(passwordType)) {
hashed = true;
}
WSUsernameTokenPrincipalImpl principal = new WSUsernameTokenPrincipalImpl(username, hashed);
if (nonce != null) {
principal.setNonce(nonce.getBytes(StandardCharsets.UTF_8));
}
principal.setPassword(passwordValue);
principal.setCreatedTime(createdTime);
principal.setPasswordType(passwordType);
return principal;
}
use of org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl in project testcases by coheigea.
the class SpringSecurityBasicAuthInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
String name = null;
if (policy != null) {
name = policy.getUserName();
}
String error = "No user credentials are available";
LOG.warning(error + " " + "for name: " + name);
throw new SecurityException(error);
}
try {
UsernameToken token = convertPolicyToToken(policy);
Credential credential = new Credential();
credential.setUsernametoken(token);
RequestData data = new RequestData();
data.setMsgContext(message);
credential = validator.validate(credential, data);
// Create a Principal/SecurityContext
Principal p = null;
if (credential != null && credential.getPrincipal() != null) {
p = credential.getPrincipal();
} else {
p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
((WSUsernameTokenPrincipalImpl) p).setPassword(policy.getPassword());
}
message.put(SecurityContext.class, createSecurityContext(p));
} catch (Exception ex) {
throw new Fault(ex);
}
}
Aggregations