本文整理汇总了Java中org.jboss.security.SecurityContext类的典型用法代码示例。如果您正苦于以下问题:Java SecurityContext类的具体用法?Java SecurityContext怎么用?Java SecurityContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityContext类属于org.jboss.security包,在下文中一共展示了SecurityContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doAs
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* Executes the privileged action as the specified user
*
* @param username
* the username
* @param password
* the password
* @param action
* the action to run
* @param <T>
* the actions return type
* @return the value returned by the action's run method.
* @throws OmakaseRuntimeException
* if the action throws an exception.
*/
public static <T> T doAs(String username, String password, PrivilegedExceptionAction<T> action) {
return Throwables.returnableInstance(() -> {
SecurityContext incomingSecurityContext = SecurityContextAssociation.getSecurityContext();
LoginContext loginContext = OmakaseLoginContextFactory.createLoginContext(username, password);
loginContext.login();
try {
Subject subject = loginContext.getSubject();
SecurityContext doAsSecurityContext = SecurityContextFactory
.createSecurityContext(new SimplePrincipal(username), password, subject,
OmakaseLoginContextFactory.SECURITY_DOMAIN);
SecurityContextAssociation.setSecurityContext(doAsSecurityContext);
return Subject.doAs(subject, action);
} finally {
loginContext.logout();
SecurityContextAssociation.setSecurityContext(incomingSecurityContext);
}
});
}
开发者ID:projectomakase,项目名称:omakase,代码行数:34,代码来源:OmakaseSecurity.java
示例2: login
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* Performs the login association between the caller and the resource for a
* 1 to 1 mapping. This acts as a login propagation strategy and is useful
* for single-sign on requirements
*
* @return True if authentication succeeds
* @throws LoginException
*/
public boolean login() throws LoginException {
SecurityContext sc = SecurityActions.getSecurityContext();
SubjectInfo si = sc.getSubjectInfo();
Subject subject = si.getAuthenticatedSubject();
Set<Principal> principals = subject.getPrincipals();
this.principal = principals.iterator().next();
if (super.login() == true) {
return true;
}
LogManager.logDetail(LogConstants.CTX_SECURITY, "Adding Passthrough principal="+principal.getName()); //$NON-NLS-1$
// Put the principal name into the sharedState map
sharedState.put("javax.security.auth.login.name", principal.getName()); //$NON-NLS-1$
sharedState.put("javax.security.auth.login.password", ""); //$NON-NLS-1$ //$NON-NLS-2$
super.loginOk = true;
return true;
}
开发者ID:kenweezy,项目名称:teiid,代码行数:31,代码来源:AssosiateCallerIdentityLoginModule.java
示例3: authenticate
import org.jboss.security.SecurityContext; //导入依赖的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
示例4: getActiveSubject
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/** Get the currently authenticated Subject. This is a thread local
property shared across all JaasSecurityManager instances.
@return The Subject authenticated in the current thread if one
exists, null otherwise.
*/
public Subject getActiveSubject()
{
/* This does not use SubjectActions.getActiveSubject since the caller
must have the correct permissions to access the
SecurityAssociation.getSubject method.
*/
//return SecurityAssociation.getSubject();
Subject subj = null;
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
if(sc != null)
{
subj = sc.getUtil().getSubject();
}
return subj;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:JaasSecurityManagerBase.java
示例5: push
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void push(Principal principal, Object credential, Subject subject,
String securityDomain)
{
//SecurityAssociation.pushSubjectContext(subject, principal, credential);
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
if(sc == null)
{
try
{
sc = SecurityContextFactory.createSecurityContext(principal, credential,
subject, securityDomain);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
else
{
sc.getUtil().createSubjectInfo(principal, credential, subject);
}
SecurityContextAssociation.setSecurityContext(sc);
}
开发者ID:picketbox,项目名称:picketbox,代码行数:24,代码来源:SubjectActions.java
示例6: getContextLoginException
import org.jboss.security.SecurityContext; //导入依赖的package包/类
static LoginException getContextLoginException()
{
LoginException exp = null;
SecurityContext sc = getSecurityContext();
if (sc != null) {
Map<String, Object> ctxInfo = sc.getData();
if (ctxInfo != null) {
for (Object obj: ctxInfo.values()) {
if (obj != null && obj instanceof LoginException) {
return (LoginException)obj;
}
}
}
}
return exp;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:SubjectActions.java
示例7: getPrincipal
import org.jboss.security.SecurityContext; //导入依赖的package包/类
static Principal getPrincipal()
{
return AccessController.doPrivileged(new PrivilegedAction<Principal>()
{
public Principal run()
{
Principal principal = null;
SecurityContext sc = getSecurityContext();
if(sc != null)
{
principal = sc.getUtil().getUserPrincipal();
}
return principal;
}
});
}
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:SubjectActions.java
示例8: getCredential
import org.jboss.security.SecurityContext; //导入依赖的package包/类
static Object getCredential()
{
return AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
Object credential = null;
SecurityContext sc = getSecurityContext();
if(sc != null)
{
credential = sc.getUtil().getCredential();
}
return credential;
}
});
}
开发者ID:picketbox,项目名称:picketbox,代码行数:17,代码来源:SubjectActions.java
示例9: isTrusted
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* @see IdentityTrustManager#isTrusted(org.jboss.security.SecurityContext)
*/
public TrustDecision isTrusted(SecurityContext securityContext)
{
if(securityContext == null)
throw PicketBoxMessages.MESSAGES.invalidNullArgument("securityContext");
if(this.identityTrustContext == null)
this.identityTrustContext = new JBossIdentityTrustContext(securityDomain, securityContext);
TrustDecision td = TrustDecision.NotApplicable;
if(this.identityTrustContext == null)
throw PicketBoxMessages.MESSAGES.invalidNullProperty("identityTrustContext");
try
{
td = this.identityTrustContext.isTrusted();
}
catch (IdentityTrustException e)
{
PicketBoxLogger.LOGGER.debugIgnoredException(e);
}
return td;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:24,代码来源:JBossIdentityTrustManager.java
示例10: 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));
}
开发者ID:picketbox,项目名称:picketbox,代码行数:26,代码来源:LdapRoleMappingProviderTestCase.java
示例11: testClientWithExistingSecurityContext
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void testClientWithExistingSecurityContext() throws Exception
{
SecurityContext prev = SecurityContextFactory.createSecurityContext("TEST");
SecurityContextAssociation.setSecurityContext(prev);
SecurityClient client = SecurityClientFactory.getSecurityClient();
assertEquals("JBossSecurityClient", JBossSecurityClient.class,client.getClass());
client.setSimple("anil", "pass");
client.login();
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
assertNotNull("SecurityContext is not null", sc);
SubjectInfo si = sc.getSubjectInfo();
assertNotNull("SubjectInfo is not null", si);
assertNotNull("Principal is not null", sc.getUtil().getUserPrincipal());
assertEquals("Principal==anil", "anil", sc.getUtil().getUserPrincipal().getName());
assertNotNull("Cred is not null", sc.getUtil().getCredential());
assertEquals("Cred==pass", "pass", sc.getUtil().getCredential());
client.logout();
assertEquals(prev, SecurityContextAssociation.getSecurityContext());
}
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:JBossSecurityClientTestCase.java
示例12: testSetIdentity
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void testSetIdentity() throws Exception
{
SecurityContext sc = SecurityContextFactory.createSecurityContext("Test");
Identity i1 = new Identity1();
Identity i2 = new Identity2();
SecurityContextUtil util = sc.getUtil();
util.addIdentity(i1);
util.addIdentity(i2);
Set<Identity> s1 = util.getIdentities(Identity1.class);
Set<Identity> s2 = util.getIdentities(Identity2.class);
assertEquals(1,s1.size());
assertEquals(1,s2.size());
assertTrue(s1.contains(i1));
assertTrue(s2.contains(i2));
}
开发者ID:picketbox,项目名称:picketbox,代码行数:20,代码来源:IdentityUnitTestCase.java
示例13: testSingleThreaded
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void testSingleThreaded() throws Exception
{
System.out.println("+++ testSingleThreaded");
UsernamePasswordHandler handler = new UsernamePasswordHandler("jduke",
"theduke");
LoginContext lc = new LoginContext("testSingleThreaded", handler);
lc.login();
Subject subject = lc.getSubject();
System.out.println("LC.Subject: "+subject);
Principal theduke = new SimplePrincipal("jduke");
assertTrue("Principals contains theduke", subject.getPrincipals().contains(theduke));
Principal saPrincipal = SecurityContextAssociation.getPrincipal();
assertTrue("SecurityContextAssociation.getPrincipal == theduke", saPrincipal.equals(theduke));
char[] password = (char[]) SecurityContextAssociation.getCredential();
assertTrue("password == theduke",
Arrays.equals(password, "theduke".toCharArray()));
assertTrue("Client side association?", SecurityContextAssociation.isClient());
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
assertNotNull("SecurityContext not null", sc);
assertEquals("jduke", sc.getUtil().getUserPrincipal().getName());
}
开发者ID:picketbox,项目名称:picketbox,代码行数:24,代码来源:ClientLoginModuleUnitTestCase.java
示例14: setUp
import org.jboss.security.SecurityContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setUp() throws Exception
{
factory = AuthConfigFactory.getFactory();
factory.registerConfigProvider(new JBossAuthConfigProvider(new HashMap(), null), layer, appId,
"Test Config Provider");
SecurityContext jsc = new JBossSecurityContext("conf-jaspi");
SecurityContextAssociation.setSecurityContext(jsc);
XMLLoginConfigImpl xli = XMLLoginConfigImpl.getInstance();
SecurityActions.setJAASConfiguration(xli);
URL configURL = Thread.currentThread().getContextClassLoader().getResource(configFile);
assertNotNull("Config URL", configURL);
xli.setConfigURL(configURL);
xli.loadConfig();
}
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:JASPIWorkflowUnitTestCase.java
示例15: setUp
import org.jboss.security.SecurityContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void setUp() throws Exception
{
factory = AuthConfigFactory.getFactory();
factory.registerConfigProvider(new JBossAuthConfigProvider(new HashMap(), null), layer, appId,
"Test Config Provider");
jaspiManager = new JASPIServerAuthenticationManager("conf-jaspi", new JBossCallbackHandler());
SecurityContext jsc = new JBossSecurityContext("conf-jaspi");
SecurityContextAssociation.setSecurityContext(jsc);
XMLLoginConfigImpl xli = XMLLoginConfigImpl.getInstance();
SecurityActions.setJAASConfiguration(xli);
URL configURL = Thread.currentThread().getContextClassLoader().getResource(configFile);
assertNotNull("Config URL", configURL);
xli.setConfigURL(configURL);
xli.loadConfig();
}
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:JASPIServerAuthenticationManagerUnitTestCase.java
示例16: testCreateSubjectInfo
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void testCreateSubjectInfo() throws Exception
{
Principal thePrincipal = new Principal()
{
public String getName()
{
return "Anil";
}
};
Subject theSubject = new Subject();
theSubject.getPrincipals().add(thePrincipal);
SecurityContext sc = SecurityContextFactory.createSecurityContext("TEST",
TestSecurityContext.class.getCanonicalName());
sc.getUtil().createSubjectInfo(thePrincipal, "pass", theSubject);
assertEquals(thePrincipal, sc.getUtil().getUserPrincipal());
assertEquals("pass", sc.getUtil().getCredential());
assertEquals(theSubject, sc.getUtil().getSubject());
}
开发者ID:picketbox,项目名称:picketbox,代码行数:21,代码来源:SubjectInfoUnitTestCase.java
示例17: push
import org.jboss.security.SecurityContext; //导入依赖的package包/类
public void push(final Principal principal, final Object credential, final Subject subject,
final String securityDomain)
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
if (sc == null)
{
try
{
sc = SecurityContextFactory.createSecurityContext(principal, credential, subject,
securityDomain);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
SecurityContextAssociation.setSecurityContext(sc);
return null;
}
});
}
开发者ID:picketbox,项目名称:picketbox,代码行数:26,代码来源:SubjectActions.java
示例18: establishSecurityContext
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* Establish a security context on the thread
* @param securityDomainName
*/
public static SecurityContext establishSecurityContext(String securityDomainName)
{
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission(SecurityFactory.class.getName() + ".establishSecurityContext"));
}
SecurityContext securityContext = null;
try
{
securityContext = SecurityContextFactory.createSecurityContext(securityDomainName);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
SecurityActions.setSecurityContext(securityContext);
return securityContext;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:SecurityFactory.java
示例19: getCallerPrincipal
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* Get the authenticated principal
* @return
* @throws PicketBoxProcessingException
*/
public Principal getCallerPrincipal() throws PicketBoxProcessingException
{
Principal principal = null;
SecurityContext securityContext = null;
try
{
securityContext = SecurityActions.getSecurityContext();
}
catch (PrivilegedActionException pae)
{
throw new PicketBoxProcessingException(pae.getCause());
}
if(securityContext != null)
principal = securityContext.getUtil().getUserPrincipal();
return principal;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:PicketBoxProcessor.java
示例20: getCallerRoles
import org.jboss.security.SecurityContext; //导入依赖的package包/类
/**
* Get the caller roles
* @return
* @throws PicketBoxProcessingException
*/
public RoleGroup getCallerRoles() throws PicketBoxProcessingException
{
RoleGroup roleGroup = null;
SecurityContext securityContext = null;
try
{
securityContext = SecurityActions.getSecurityContext();
}
catch (PrivilegedActionException pae)
{
throw new PicketBoxProcessingException(pae.getCause());
}
if(securityContext != null)
roleGroup = securityContext.getUtil().getRoles();
return roleGroup;
}
开发者ID:picketbox,项目名称:picketbox,代码行数:23,代码来源:PicketBoxProcessor.java
注:本文中的org.jboss.security.SecurityContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论