本文整理汇总了Java中org.jboss.security.SimplePrincipal类的典型用法代码示例。如果您正苦于以下问题:Java SimplePrincipal类的具体用法?Java SimplePrincipal怎么用?Java SimplePrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimplePrincipal类属于org.jboss.security包,在下文中一共展示了SimplePrincipal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: aroundInvoke
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
KeycloakToken keycloakToken = null;
Map<String, Object> contextData = invocationContext.getContextData();
if (contextData.containsKey(KeycloakToken.TOKEN_KEY)) {
keycloakToken = (KeycloakToken) contextData.get(KeycloakToken.TOKEN_KEY);
logger.info("Successfully found KeycloakToken passed from client");
ContextStateCache stateCache = null;
try {
try {
// We have been requested to use an authentication token so now we attempt the switch.
// This userPrincipal and credential will be found by JAAS login modules
SimplePrincipal userPrincipal = new SimplePrincipal(keycloakToken.getUsername());
String accessToken = keycloakToken.getToken();
stateCache = SecurityActions.pushIdentity(userPrincipal, accessToken);
logger.infof("Successfully pushed userPrincipal %s and his credential", userPrincipal.getName());
} catch (Exception e) {
logger.error("Failed to switch security context for user", e);
// Don't propagate the exception stacktrace back to the client for security reasons
throw new EJBAccessException("Unable to attempt switching of user.");
}
return invocationContext.proceed();
} finally {
// switch back to original context
if (stateCache != null) {
SecurityActions.popIdentity(stateCache);
;
}
}
} else {
logger.warn("No Keycloak token found");
return invocationContext.proceed();
}
}
示例2: checkPrincipal
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public boolean checkPrincipal(Object identity) {
if (identity != null && identity instanceof OIDCPrincipal) {
super.loginOk = true;
this.identity = (OIDCPrincipal) identity;
Group roles = new SimpleGroup(SecurityConstants.ROLES_IDENTIFIER);
if (identity != null && rolesClaimName != null) {
Object rolesClaim = this.identity.getClaims().get(rolesClaimName);
if (rolesClaim instanceof JSONArray) {
((List<String>) rolesClaim).forEach(r -> roles.addMember(new SimplePrincipal(r)));
}
}
this.roleSets = new Group[] { roles };
return true;
}
return false;
}
示例3: createIdentity
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
/**
* Modificado para obtener principal customizado
*/
protected Principal createIdentity(String username) throws Exception {
// Usuario unautenticado
if (username != null && username.equals( (String) options.get("unauthenticatedIdentity"))){
log.debug ("Creating MockPrincipal para "+username);
return new MockPrincipal(username,"","",'A');
}
// Usuario autenticado
UserInfo ui = getUserInfo(username);
if ( ui == null)
{
// Se llama para crear principals asociados a los roles
return new SimplePrincipal (username);
}
else
{
log.debug ("Creating MockPrincipal para "+username);
return new MockPrincipal(username,ui.fullName,ui.nif,'U');
}
}
示例4: getIdentity
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@Override
protected Principal getIdentity() {
log.debug("Getting Identity");
HttpServletRequest request = null;
try {
request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
} catch (PolicyContextException e) {
log.error("Could not load HttpServletRequest", e);
return null;
}
if (request == null) {
return null;
}
return new SimplePrincipal((String) request.getAttribute("UNISON_USER"));
}
示例5: authenticate
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@Override
public SecurityContext authenticate(String domain,
String baseUsername, Credentials credentials, String applicationName) throws LoginException {
// If username specifies a domain ([email protected]) only that domain is authenticated against.
SecurityDomainContext securityDomainContext = getSecurityDomainContext(domain);
if (securityDomainContext != null) {
AuthenticationManager authManager = securityDomainContext.getAuthenticationManager();
if (authManager != null) {
Principal userPrincipal = new SimplePrincipal(baseUsername);
Subject subject = new Subject();
String credString = credentials==null?null:new String(credentials.getCredentialsAsCharArray());
boolean isValid = authManager.isValid(userPrincipal, credString, subject);
if (isValid) {
SecurityContext securityContext = createSecurityContext(domain, userPrincipal, credString, subject);
LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] {"Logon successful for \"", baseUsername, "\" in security domain", domain}); //$NON-NLS-1$ //$NON-NLS-2$
return securityContext;
}
}
}
throw new LoginException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50072, baseUsername, domain ));
}
示例6: getPrincipalSetFromRole
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
private Set<Principal> getPrincipalSetFromRole(Role role)
{
Set<Principal> principalsSet = new HashSet<Principal>();
if(role instanceof RoleGroup)
{
RoleGroup rg = (RoleGroup) role;
Collection<Role> rolesList = rg.getRoles();
for(Role r: rolesList)
{
principalsSet.add(new SimplePrincipal(r.getRoleName()));
}
}
else
principalsSet.add(new SimplePrincipal(role.getRoleName()));
return principalsSet;
}
示例7: commit
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@Override
public boolean commit() throws LoginException
{
Principal principal = new SimplePrincipal(username);
SubjectActions.addPrincipals(subject, principal);
sharedState.put("javax.security.auth.login.name", username);
// Decode the encrypted password
try
{
char[] decodedPassword = decode(password);
PasswordCredential cred = new PasswordCredential(username, decodedPassword);
SubjectActions.addCredentials(subject, cred);
}
catch(Exception e)
{
LoginException le = new LoginException(e.getLocalizedMessage());
le.initCause(e);
throw le;
}
return true;
}
示例8: commit
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean commit() throws LoginException
{
Principal principal = new SimplePrincipal(username);
SubjectActions.addPrincipals(subject, principal);
sharedState.put("javax.security.auth.login.name", username);
// Decode the encrypted password
try
{
char[] decodedPassword = decode(password);
PasswordCredential cred = new PasswordCredential(username, decodedPassword);
SubjectActions.addCredentials(subject, cred);
}
catch(Exception e)
{
LoginException le = new LoginException(e.getLocalizedMessage());
le.initCause(e);
throw le;
}
return true;
}
示例9: login
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
@Override
public boolean login() throws LoginException
{
PicketBoxLogger.LOGGER.traceBeginLogin();
if (super.login())
return true;
Principal principal = new SimplePrincipal(principalName);
SubjectActions.addPrincipals(subject, principal);
// Put the principal name into the sharedState map
sharedState.put("javax.security.auth.login.name", principalName);
PasswordCredential cred = new PasswordCredential(userName, password.toCharArray());
SubjectActions.addCredentials(subject, cred);
super.loginOk = true;
return true;
}
示例10: commit
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public boolean commit() throws LoginException
{
Principal principal = new SimplePrincipal(username);
SubjectActions.addPrincipals(subject, principal);
sharedState.put("javax.security.auth.login.name", username);
// Decode the encrypted password
// try
// {
// char[] decodedPassword = DecodeAction.decode(password,
// jaasSecurityDomain, getServer());
// PasswordCredential cred = new PasswordCredential(username, decodedPassword);
// cred.setManagedConnectionFactory(getMcf());
// SubjectActions.addCredentials(subject, cred);
// }
// catch(Exception e)
// {
// throw new LoginException(ErrorCodes.PROCESSING_FAILED + "Failed to decode password: " + e.getMessage());
// }
return true;
}
示例11: testValidWebAuthorization
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public void testValidWebAuthorization() throws Exception
{
//Create a ContextMap
Map<String,Object> contextMap = new HashMap<String,Object>();
HttpServletRequest request = new TestHttpServletRequest(new SimplePrincipal("someprincipal"),
"/someuri", "GET");
RoleGroup roleGroup = SecurityTestUtil.getRoleGroup(new String[]{"roleA", "roleC"});
//Add good roles to the context
sc.getUtil().setRoles(roleGroup);
boolean result = wah.checkResourcePermission(contextMap,
request,
getDummyResponse(),
new Subject(),
"web.jar",
"/someuri");
assertTrue("Web Authz", result);
}
示例12: testInvalidWebAuthorization
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public void testInvalidWebAuthorization() throws Exception
{
//Create a ContextMap
Map<String,Object> contextMap = new HashMap<String,Object>();
HttpServletRequest request = new TestHttpServletRequest(new SimplePrincipal("someprincipal"),
"/someuri", "GET");
RoleGroup roleGroup = SecurityTestUtil.getRoleGroup(new String[]{"Villain"});
//Add good roles to the context
sc.getUtil().setRoles(roleGroup);
boolean result = wah.checkResourcePermission(contextMap,
request,
getDummyResponse(),
new Subject(),
"web.jar",
"/someuri");
assertFalse("Invalid Web Authz", result);
}
示例13: testValidAuthorization
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public void testValidAuthorization() throws Exception
{
Principal ejbPrincipal = new SimplePrincipal("AuthenticatedPrincipal");
Subject callerSubject = new Subject();
callerSubject.getPrincipals().add(ejbPrincipal);
RoleGroup roleGroup = SecurityTestUtil.getRoleGroup(new String[]{"roleA", "roleC"});
//Add good roles to the context
sc.getUtil().setRoles(roleGroup);
boolean result = eah.authorize("TestEJB",
DummyClass.class.getMethod("someMethod", new Class[0]),
ejbPrincipal,
"void someMethod",
this.getClass().getProtectionDomain().getCodeSource(),
callerSubject,
null,
"ejb.jar",
methodRoleGroup);
assertTrue("Authz", result);
}
示例14: testInvalidAuthorization
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public void testInvalidAuthorization() throws Exception
{
Principal ejbPrincipal = new SimplePrincipal("AuthenticatedPrincipal");
Subject callerSubject = new Subject();
callerSubject.getPrincipals().add(ejbPrincipal);
RoleGroup roleGroup = SecurityTestUtil.getRoleGroup(new String[]{"villain"});
//Add good roles to the context
sc.getUtil().setRoles(roleGroup);
boolean result = eah.authorize("TestEJB",
DummyClass.class.getMethod("someMethod", new Class[0]),
ejbPrincipal,
"void someMethod",
this.getClass().getProtectionDomain().getCodeSource(),
callerSubject,
null,
"ejb.jar",
methodRoleGroup);
assertFalse("InvalidAuthz", result);
}
示例15: testRoleRecursion
import org.jboss.security.SimplePrincipal; //导入依赖的package包/类
public void testRoleRecursion() throws Exception {
StaxBasedConfigParser parser = new StaxBasedConfigParser();
parser.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("ldap/ldap-role-mapping-config.xml"));
SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
MappingManager mm = sc.getMappingManager();
assertNotNull("MappingManager == null", mm);
MappingContext<RoleGroup> mc = mm.getMappingContext(MappingType.ROLE.name());
assertNotNull("MappingContext == null", mc);
assertTrue(mc.hasModules());
HashMap<String, Object> map = new HashMap<>();
map.put(SecurityConstants.PRINCIPAL_IDENTIFIER, new SimplePrincipal("jduke"));
MappingProvider<RoleGroup> provider = mc.getModules().get(0);
RoleGroup roleGroup = new SimpleRoleGroup("roles");
provider.performMapping(map, roleGroup);
Collection<Role> roles = roleGroup.getRoles();
assertEquals(roles.size(), 4);
List<Role> correctRoles = new ArrayList<>();
for (int i = 1; i < 5; i++)
correctRoles.add(new SimpleRole("R"+i));
assertTrue(roles.containsAll(correctRoles));
}