use of org.apache.wss4j.dom.message.token.UsernameToken in project cxf by apache.
the class UsernameTokenPolicyValidator method checkTokens.
/**
* All UsernameTokens must conform to the policy
*/
public boolean checkTokens(org.apache.wss4j.policy.model.UsernameToken usernameTokenPolicy, AssertionInfo ai, List<WSSecurityEngineResult> utResults) {
for (WSSecurityEngineResult result : utResults) {
UsernameToken usernameToken = (UsernameToken) result.get(WSSecurityEngineResult.TAG_USERNAME_TOKEN);
PasswordType passwordType = usernameTokenPolicy.getPasswordType();
boolean isHashPassword = passwordType == PasswordType.HashPassword;
boolean isNoPassword = passwordType == PasswordType.NoPassword;
if (isHashPassword != usernameToken.isHashed()) {
ai.setNotAsserted("Password hashing policy not enforced");
return false;
}
if (isNoPassword && (usernameToken.getPassword() != null)) {
ai.setNotAsserted("Username Token NoPassword policy not enforced");
return false;
} else if (!isNoPassword && (usernameToken.getPassword() == null) && isNonEndorsingSupportingToken(usernameTokenPolicy)) {
ai.setNotAsserted("Username Token No Password supplied");
return false;
}
if (usernameTokenPolicy.isCreated() && (usernameToken.getCreated() == null || usernameToken.isHashed())) {
ai.setNotAsserted("Username Token Created policy not enforced");
return false;
}
if (usernameTokenPolicy.isNonce() && (usernameToken.getNonce() == null || usernameToken.isHashed())) {
ai.setNotAsserted("Username Token Nonce policy not enforced");
return false;
}
}
return true;
}
use of org.apache.wss4j.dom.message.token.UsernameToken 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.dom.message.token.UsernameToken in project cxf by apache.
the class WSSUsernameCallbackHandler method createWSSEUsernameToken.
private UsernameToken createWSSEUsernameToken(String username, Document doc) {
UsernameToken usernameToken = new UsernameToken(true, doc, null);
usernameToken.setName(username);
usernameToken.addWSUNamespace();
usernameToken.addWSSENamespace();
usernameToken.setID("id-" + username);
return usernameToken;
}
use of org.apache.wss4j.dom.message.token.UsernameToken in project cxf by apache.
the class CallbackHandlerLoginHandler method createSubject.
@Override
public UserSubject createSubject(Client client, String user, String pass) {
Document doc = DOMUtils.getEmptyDocument();
UsernameToken token = new UsernameToken(false, doc, WSS4JConstants.PASSWORD_TEXT);
token.setName(user);
token.setPassword(pass);
Credential credential = new Credential();
credential.setUsernametoken(token);
RequestData data = new RequestData();
data.setMsgContext(PhaseInterceptorChain.getCurrentMessage());
data.setCallbackHandler(callbackHandler);
UsernameTokenValidator validator = new UsernameTokenValidator();
try {
credential = validator.validate(credential, data);
UserSubject subject = new UserSubject();
subject.setLogin(user);
return subject;
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
use of org.apache.wss4j.dom.message.token.UsernameToken in project ddf by codice.
the class StsIssueTest method testBearerWebSsoTokenSaml2.
/**
* Test the Web SSO Token
*/
public void testBearerWebSsoTokenSaml2(StsPortTypes portType) throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = StsIssueTest.class.getResource("/cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
SpringBusFactory.setDefaultBus(bus);
SpringBusFactory.setThreadDefaultBus(bus);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
// Create a Username Token
UsernameToken oboToken = new UsernameToken(false, doc, WSConstants.PASSWORD_TEXT);
// Workout the details of how to fill out the username token
// ID - the Key that tells the validator its an SSO token
// Name - the SSO ticket
oboToken.setID(CAS_ID);
oboToken.setName("ST-098ASDF13245WERT");
// Build the Claims object
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.writeStartElement(WST, CLAIMS, STSUtils.WST_NS_05_12);
writer.writeNamespace(WST, STSUtils.WST_NS_05_12);
writer.writeNamespace(IC, IDENTITY_URI);
writer.writeAttribute(DIALECT, IDENTITY_URI);
// Add the Role claim
writer.writeStartElement(IC, CLAIM_TYPE, IDENTITY_URI);
// writer.writeAttribute("Uri",
// "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
writer.writeAttribute(URI, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uid");
writer.writeEndElement();
Element claims = writer.getDocument().getDocumentElement();
// Get a token
SecurityToken token = requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, oboToken.getElement(), bus, StsAddresses.valueOf(portType.toString()).toString(), WsdlLocations.valueOf(portType.toString()).toString(), EndPoints.valueOf(portType.toString()).toString(), claims);
if (token != null) {
validateSecurityToken(token);
}
bus.shutdown(true);
}
Aggregations