当前位置: 首页>>代码示例>>Java>>正文


Java SimplePrincipal类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:mposolda,项目名称:keycloak-remote-ejb,代码行数:40,代码来源:ServerSecurityInterceptor.java

示例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;
}
 
开发者ID:aaronanderson,项目名称:swarm-oidc,代码行数:19,代码来源:OIDCLoginModule.java

示例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');
	}

}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:26,代码来源:MockDatabaseLoginModule.java

示例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"));
	
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:19,代码来源:UnisonLoginModule.java

示例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 ));       
   }
 
开发者ID:kenweezy,项目名称:teiid,代码行数:22,代码来源:JBossSecurityHelper.java

示例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;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:AbstractJACCModuleDelegate.java

示例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;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:22,代码来源:SecureIdentityLoginModule.java

示例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;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:PBEIdentityLoginModule.java

示例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;
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:ConfiguredIdentityLoginModule.java

示例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;
   }
 
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:JaasSecurityDomainIdentityLoginModule.java

示例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);
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:WebAuthorizationHelperUnitTestCase.java

示例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); 
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:WebAuthorizationHelperUnitTestCase.java

示例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);
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:24,代码来源:EJBAuthorizationHelperUnitTestCase.java

示例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);
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:24,代码来源:EJBAuthorizationHelperUnitTestCase.java

示例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));
}
 
开发者ID:picketbox,项目名称:picketbox,代码行数:26,代码来源:LdapRoleMappingProviderTestCase.java


注:本文中的org.jboss.security.SimplePrincipal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。