use of javax.security.jacc.PolicyContextException in project javaee7-samples by javaee-samples.
the class SubjectServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");
if (subject != null) {
response.getWriter().print("Obtained subject from context.\n");
// Get the permissions associated with the Subject we obtained
PermissionCollection permissionCollection = getPermissionCollection(subject);
// Resolve any potentially unresolved permissions
permissionCollection.implies(new WebRoleRefPermission("", "nothing"));
// Filter just the roles from all the permissions, which may include things like
// java.net.SocketPermission, java.io.FilePermission, and obtain the actual role names.
Set<String> roles = filterRoles(request, permissionCollection);
for (String role : roles) {
response.getWriter().print("User has role " + role + "\n");
}
}
} catch (PolicyContextException e) {
e.printStackTrace(response.getWriter());
}
}
use of javax.security.jacc.PolicyContextException in project tomee by apache.
the class JaccPermissionsBuilder method install.
public void install(final PolicyContext policyContext) throws OpenEJBException {
if (SystemInstance.get().hasProperty("openejb.geronimo")) {
return;
}
try {
final PolicyConfigurationFactory factory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
final PolicyConfiguration policy = factory.getPolicyConfiguration(policyContext.getContextID(), false);
policy.addToExcludedPolicy(policyContext.getExcludedPermissions());
policy.addToUncheckedPolicy(policyContext.getUncheckedPermissions());
for (final Map.Entry<String, PermissionCollection> entry : policyContext.getRolePermissions().entrySet()) {
policy.addToRole(entry.getKey(), entry.getValue());
}
policy.commit();
} catch (final ClassNotFoundException e) {
throw new OpenEJBException("PolicyConfigurationFactory class not found", e);
} catch (final PolicyContextException e) {
throw new OpenEJBException("JACC PolicyConfiguration failed: ContextId=" + policyContext.getContextID(), e);
}
}
use of javax.security.jacc.PolicyContextException in project hibernate-orm by hibernate.
the class StandardJaccServiceImpl method addPermission.
@Override
public void addPermission(GrantedPermission permissionDeclaration) {
if (policyConfiguration == null) {
policyConfiguration = locatePolicyConfiguration(contextId);
}
for (String grantedAction : permissionDeclaration.getPermissibleAction().getImpliedActions()) {
final EJBMethodPermission permission = new EJBMethodPermission(permissionDeclaration.getEntityName(), grantedAction, // interfaces
null, // arguments
null);
log.debugf("Adding permission [%s] to role [%s]", grantedAction, permissionDeclaration.getRole());
try {
policyConfiguration.addToRole(permissionDeclaration.getRole(), permission);
} catch (PolicyContextException pce) {
throw new HibernateException("policy context exception occurred", pce);
}
}
}
Aggregations