本文整理汇总了Java中org.jboss.security.SecurityContext.getMappingManager方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContext.getMappingManager方法的具体用法?Java SecurityContext.getMappingManager怎么用?Java SecurityContext.getMappingManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.security.SecurityContext
的用法示例。
在下文中一共展示了SecurityContext.getMappingManager方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRoleRecursion
import org.jboss.security.SecurityContext; //导入方法依赖的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));
}
示例2: testX509
import org.jboss.security.SecurityContext; //导入方法依赖的package包/类
public void testX509() throws Exception
{
ApplicationPolicy ap = SecurityConfiguration.getApplicationPolicy("test");
MappingModuleEntry mme = new MappingModuleEntry(SubjectDNMapper.class.getName());
MappingInfo principalMappingInfo = new MappingInfo();
principalMappingInfo.add(mme);
ap.setMappingInfo(MappingType.PRINCIPAL.name(), principalMappingInfo);
String issuerDN = "CN=Fedora,OU=JBoss,O=Red Hat,C=US";
String subjectDN = "CN=Anil,OU=JBoss,O=Red Hat,C=US";
Principal x509 = new SimplePrincipal("CN=Fedora, OU=JBoss, O=Red Hat, C=DE");
SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
MappingManager mm = sc.getMappingManager();
assertNotNull("MappingManager != null", mm);
MappingContext<Principal> mc = mm.getMappingContext(MappingType.PRINCIPAL.name());
assertNotNull("MappingContext != null", mc);
HashMap<String,Object> map = new HashMap<String,Object>();
X509Certificate cert = getX509Certificate(issuerDN,subjectDN);
X509Certificate[] certs = new X509Certificate[]{cert};
map.put("X509", certs);
mc.performMapping(map, x509);
Principal mappedPrincipal = (Principal) mc.getMappingResult().getMappedObject();
assertEquals(subjectDN,mappedPrincipal.getName());
}
示例3: getCurrentRoles
import org.jboss.security.SecurityContext; //导入方法依赖的package包/类
private RoleGroup getCurrentRoles(Principal principal, Subject subject, SecurityContext securityContext)
{
if(subject == null)
throw PicketBoxMessages.MESSAGES.invalidNullArgument("subject");
if(securityContext == null)
throw PicketBoxMessages.MESSAGES.invalidNullArgument("securityContext");
Group subjectRoles = getGroupFromSubject(subject);
boolean emptyContextRoles = false;
RoleGroup userRoles = securityContext.getUtil().getRoles();
//Group userRoles = (Group)sc.getData().get(ROLES_IDENTIFIER);
if(userRoles == null || "true".equalsIgnoreCase(SubjectActions.getRefreshSecurityContextRoles()))
emptyContextRoles = true;
userRoles = copyGroups(userRoles, subjectRoles);
/**
* Update the roles in the SecurityContext and
* allow mapping rules be applied only if the SC roles
* and the subject roles are not the same
*/
if(subjectRoles != userRoles || emptyContextRoles)
{
MappingManager mm = securityContext.getMappingManager();
MappingContext<RoleGroup> mc = mm.getMappingContext(MappingType.ROLE.name());
RoleGroup mappedUserRoles = userRoles;
if(mc != null && mc.hasModules())
{
Map<String,Object> contextMap = new HashMap<String,Object>();
contextMap.put(SecurityConstants.ROLES_IDENTIFIER, userRoles);
if(principal != null)
contextMap.put(SecurityConstants.PRINCIPAL_IDENTIFIER, principal);
//Append any deployment role->principals configuration done by the user
contextMap.put(SecurityConstants.DEPLOYMENT_PRINCIPAL_ROLES_MAP,
SecurityRolesAssociation.getSecurityRoles());
//Append the principals also
contextMap.put(SecurityConstants.PRINCIPALS_SET_IDENTIFIER, subject.getPrincipals());
if (PicketBoxLogger.LOGGER.isTraceEnabled())
{
PicketBoxLogger.LOGGER.traceRolesBeforeMapping(userRoles != null ? userRoles.toString() : "");
}
if(userRoles == null)
userRoles = this.getEmptyRoleGroup();
mc.performMapping(contextMap, userRoles);
mappedUserRoles = mc.getMappingResult().getMappedObject();
if (PicketBoxLogger.LOGGER.isTraceEnabled())
{
PicketBoxLogger.LOGGER.traceRolesAfterMapping(userRoles.toString());
}
}
securityContext.getData().put(ROLES_IDENTIFIER, mappedUserRoles);
}
//Ensure that the security context has the roles
if(securityContext.getUtil().getRoles() == null)
securityContext.getUtil().setRoles(userRoles);
//Send the final processed (mapping applied) roles
return userRoles;
}
示例4: testLDAPAttributes
import org.jboss.security.SecurityContext; //导入方法依赖的package包/类
public void testLDAPAttributes() throws Exception
{
StaxBasedConfigParser parser = new StaxBasedConfigParser();
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("ldap/ldap-attributes-config.xml")) {
parser.parse2(is);
}
SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
MappingManager mm = sc.getMappingManager();
assertNotNull("MappingManager != null", mm);
MappingContext<List<Attribute<String>>> mc = mm.getMappingContext(MappingType.ATTRIBUTE.name());
assertNotNull("MappingContext != null", mc);
assertEquals("1 module", 1,mc.getModules().size());
HashMap<String,Object> map = new HashMap<String,Object>();
map.put(SecurityConstants.PRINCIPAL_IDENTIFIER, new SimplePrincipal("jduke"));
List<Attribute<String>> attList = new ArrayList<Attribute<String>>();
mc.performMapping(map, attList);
attList = (List<Attribute<String>>) mc.getMappingResult().getMappedObject();
boolean foundEmail = false;
boolean foundEmployeeType = false;
boolean foundEmployeeNumber = false;
assertNotNull("Attribute List is not null?", attList);
for(Attribute<String> att: attList)
{
String attName = att.getName();
if(attName.equals(Attribute.TYPE.EMAIL_ADDRESS.get()))
{
assertEquals("[email protected]",att.getValue());
foundEmail = true;
}
if(attName.equals("employeeType"))
{
assertEquals("permanent",att.getValue());
foundEmployeeType = true;
}
if(attName.equals("employeeNumber"))
{
assertEquals("007",att.getValue());
foundEmployeeNumber = true;
}
}
assertTrue("Found Email", foundEmail);
assertTrue("Found Emp Type", foundEmployeeType);
assertTrue("Found Emp Number", foundEmployeeNumber);
}
示例5: testLDAPAttributes
import org.jboss.security.SecurityContext; //导入方法依赖的package包/类
public void testLDAPAttributes() throws Exception
{
StaxBasedConfigParser parser = new StaxBasedConfigParser();
parser.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("ldap/ldap-attributes-config.xml"));
SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
MappingManager mm = sc.getMappingManager();
assertNotNull("MappingManager != null", mm);
MappingContext<List<Attribute<String>>> mc = mm.getMappingContext(MappingType.ATTRIBUTE.name());
assertNotNull("MappingContext != null", mc);
assertEquals("1 module", 1,mc.getModules().size());
HashMap<String,Object> map = new HashMap<String,Object>();
map.put(SecurityConstants.PRINCIPAL_IDENTIFIER, new SimplePrincipal("jduke"));
List<Attribute<String>> attList = new ArrayList<Attribute<String>>();
mc.performMapping(map, attList);
attList = (List<Attribute<String>>) mc.getMappingResult().getMappedObject();
boolean foundEmail = false;
boolean foundEmployeeType = false;
boolean foundEmployeeNumber = false;
assertNotNull("Attribute List is not null?", attList);
for(Attribute<String> att: attList)
{
String attName = att.getName();
if(attName.equals(Attribute.TYPE.EMAIL_ADDRESS.get()))
{
assertEquals("[email protected]",att.getValue());
foundEmail = true;
}
if(attName.equals("employeeType"))
{
assertEquals("permanent",att.getValue());
foundEmployeeType = true;
}
if(attName.equals("employeeNumber"))
{
assertEquals("007",att.getValue());
foundEmployeeNumber = true;
}
}
assertTrue("Found Email", foundEmail);
assertTrue("Found Emp Type", foundEmployeeType);
assertTrue("Found Emp Number", foundEmployeeNumber);
}
示例6: testLDAPMultiValueAttributes
import org.jboss.security.SecurityContext; //导入方法依赖的package包/类
public void testLDAPMultiValueAttributes() throws Exception
{
StaxBasedConfigParser parser = new StaxBasedConfigParser();
parser.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("ldap/ldap-attributes-config.xml"));
SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
MappingManager mm = sc.getMappingManager();
assertNotNull("MappingManager != null", mm);
MappingContext<List<Attribute<String>>> mc = mm.getMappingContext(MappingType.ATTRIBUTE.name());
assertNotNull("MappingContext != null", mc);
assertEquals("1 module", 1,mc.getModules().size());
HashMap<String,Object> map = new HashMap<String,Object>();
map.put(SecurityConstants.PRINCIPAL_IDENTIFIER, new SimplePrincipal("jduke"));
List<Attribute<String>> attList = new ArrayList<Attribute<String>>();
mc.performMapping(map, attList);
attList = (List<Attribute<String>>) mc.getMappingResult().getMappedObject();
boolean foundMobile1 = false;
boolean foundMobile2 = false;
boolean foundMobile3 = false;
assertNotNull("Attribute List is not null?", attList);
for(Attribute<String> att: attList)
{
String attName = att.getName();
if(attName.equals("mobile"))
{
if( att.getValue().equals("1") )
foundMobile1 = true;
else if( att.getValue().equals("2") )
foundMobile2 = true;
else if( att.getValue().equals("3") )
foundMobile3 = true;
}
}
assertTrue("Found mobile1", foundMobile1);
assertTrue("Found mobile2", foundMobile2);
assertTrue("Found mobile3", foundMobile3);
}