List of usage examples for org.apache.shiro.subject SubjectContext setPrincipals
void setPrincipals(PrincipalCollection principals);
From source file:com.caricah.iotracah.bootstrap.security.IOTSecurityManager.java
License:Apache License
/** * Attempts to resolve any associated session based on the context and returns a * context that represents this resolved {@code Session} to ensure it may be referenced if necessary by the * invoked {@link SubjectFactory} that performs actual {@link Subject} construction. * <p/>//w ww.j a v a 2 s . co m * If there is a {@code Session} already in the context because that is what the caller wants to be used for * {@code Subject} construction, or if no session is resolved, this method effectively does nothing * returns the context method argument unaltered. * * @param context the subject context data that may resolve a Session instance. * @return The context to use to pass to a {@link SubjectFactory} for subject creation. * @since 1.0 */ private SubjectContext resolveSession(SubjectContext context) { if (context.resolveSession() != null) { log.debug("Context already contains a session. Returning."); return context; } try { //Context couldn't resolve it directly, // let's see if we can since we have direct access to // the session manager: IOTClient session = resolveContextSession(context); if (session != null) { context.setAuthenticated(true); context.setSession(session); PrincipalCollection principles = session.getPrincipleCollection(); if (null != principles) { context.setPrincipals(principles); } } } catch (InvalidSessionException e) { log.trace("Resolved SubjectContext context session is invalid. Ignoring and creating an anonymous " + "(session-less) Subject instance.", e); } return context; }
From source file:io.vertx.ext.auth.impl.realms.ShiroAuthRealmImpl.java
License:Open Source License
@Override public boolean hasRole(String principal, String role) { SubjectContext subjectContext = new DefaultSubjectContext(); PrincipalCollection coll = new SimplePrincipalCollection(principal); subjectContext.setPrincipals(coll); Subject subject = securityManager.createSubject(subjectContext); return subject.hasRole(role); }
From source file:io.vertx.ext.auth.impl.realms.ShiroAuthRealmImpl.java
License:Open Source License
@Override public boolean hasPermission(String principal, String permission) { SubjectContext subjectContext = new DefaultSubjectContext(); PrincipalCollection coll = new SimplePrincipalCollection(principal); subjectContext.setPrincipals(coll); Subject subject = securityManager.createSubject(subjectContext); try {// ww w .j a v a 2 s .c o m subject.checkPermission(permission); return true; } catch (AuthorizationException e) { return false; } }
From source file:io.vertx.ext.auth.shiro.impl.ShiroAuthRealmBase.java
License:Open Source License
@Override public boolean hasRole(JsonObject principal, String role) { SubjectContext subjectContext = new DefaultSubjectContext(); String username = principal.getString("username"); PrincipalCollection coll = new SimplePrincipalCollection(username); subjectContext.setPrincipals(coll); Subject subject = securityManager.createSubject(subjectContext); return subject.hasRole(role); }
From source file:io.vertx.ext.auth.shiro.impl.ShiroAuthRealmBase.java
License:Open Source License
@Override public boolean hasPermission(JsonObject principal, String permission) { SubjectContext subjectContext = new DefaultSubjectContext(); String username = principal.getString("username"); PrincipalCollection coll = new SimplePrincipalCollection(username); subjectContext.setPrincipals(coll); Subject subject = securityManager.createSubject(subjectContext); try {//from w w w . jav a 2 s . c o m subject.checkPermission(permission); return true; } catch (AuthorizationException e) { return false; } }
From source file:io.vertx.ext.auth.shiro.impl.ShiroUser.java
License:Open Source License
@Override public void setAuthProvider(AuthProvider authProvider) { if (authProvider instanceof ShiroAuthProviderImpl) { ShiroAuthProviderImpl shiroAuthProvider = (ShiroAuthProviderImpl) authProvider; this.vertx = shiroAuthProvider.getVertx(); this.securityManager = shiroAuthProvider.getSecurityManager(); // generate the subject back from the provider SubjectContext subjectContext = new DefaultSubjectContext(); PrincipalCollection coll = new SimplePrincipalCollection(username, shiroAuthProvider.getRealmName()); subjectContext.setPrincipals(coll); subject = securityManager.createSubject(subjectContext); } else {/*from w w w . ja v a 2 s . co m*/ throw new IllegalArgumentException("Not a ShiroAuthProviderImpl"); } }