use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class SimpleSubjectCreatingInterceptor method createSubject.
@Override
protected Subject createSubject(String name, String password, boolean isDigest, String nonce, String created) throws SecurityException {
Subject subject = new Subject();
// delegate to the external security system if possible
String roleName = "Alice".equals(name) ? "developers" : "pms";
subject.getPrincipals().add(new SimplePrincipal(name));
subject.getPrincipals().add(new SimpleGroup(roleName, name));
subject.setReadOnly();
return subject;
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class CustomUsernameTokenInterceptor method createSubject.
protected Subject createSubject(String name, String password, boolean isDigest, String nonce, String created) throws SecurityException {
Subject subject = new Subject();
// delegate to the external security system if possible
// authenticate the user somehow
subject.getPrincipals().add(new SimplePrincipal(name));
// add roles this user is in
String roleName = "Alice".equals(name) ? "developers" : "pms";
try {
String expectedPassword = "Alice".equals(name) ? "ecilA" : UsernameTokenUtil.doPasswordDigest(XMLUtils.decode(nonce), created, "invalid-password");
if (!password.equals(expectedPassword)) {
throw new SecurityException("Wrong Password");
}
} catch (org.apache.wss4j.common.ext.WSSecurityException ex) {
throw new SecurityException("Wrong Password");
}
subject.getPrincipals().add(new SimpleGroup(roleName, name));
subject.setReadOnly();
return subject;
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class SimpleUsernameTokenInterceptor method createSubject.
protected Subject createSubject(String name, String password, boolean isDigest, String nonce, String created) throws SecurityException {
Subject subject = new Subject();
// delegate to the external security system if possible
// authenticate the user somehow
subject.getPrincipals().add(new SimplePrincipal(name));
// add roles this user is in
String roleName = "Alice".equals(name) ? "developers" : "pms";
subject.getPrincipals().add(new SimpleGroup(roleName, name));
subject.setReadOnly();
return subject;
}
use of org.apache.cxf.common.security.SimplePrincipal in project camel by apache.
the class DefaultCxfMessageMapperTest method testSecurityContext.
@Test
public void testSecurityContext() {
DefaultCxfMessageMapper mapper = new DefaultCxfMessageMapper();
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
request.getUserPrincipal();
EasyMock.expectLastCall().andReturn(new SimplePrincipal("barry"));
request.isUserInRole("role1");
EasyMock.expectLastCall().andReturn(true);
request.isUserInRole("role2");
EasyMock.expectLastCall().andReturn(false);
EasyMock.replay(request);
Exchange camelExchange = setupCamelExchange("/", "/", request);
Message cxfMessage = mapper.createCxfMessageFromCamelExchange(camelExchange, EasyMock.createMock(HeaderFilterStrategy.class));
SecurityContext sc = cxfMessage.get(SecurityContext.class);
assertNotNull(sc);
assertEquals("barry", sc.getUserPrincipal().getName());
assertTrue(sc.isUserInRole("role1"));
assertFalse(sc.isUserInRole("role2"));
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class TestUserPasswordLoginModule method login.
@Override
public boolean login() throws LoginException {
NameCallback nameCallback = new NameCallback("User");
PasswordCallback passwordCallback = new PasswordCallback("Password", false);
Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
try {
this.callbackHandler.handle(callbacks);
} catch (IOException | UnsupportedCallbackException e) {
throw new LoginException(e.getMessage());
}
String userName = nameCallback.getName();
String password = new String(passwordCallback.getPassword());
if (!TESTUSER.equals(userName)) {
throw new LoginException("wrong username");
}
if (!TESTPASS.equals(password)) {
throw new LoginException("wrong password");
}
subject.getPrincipals().add(new SimplePrincipal(userName));
subject.getPrincipals().add(new SimpleGroup(TESTGROUP));
return true;
}
Aggregations