List of usage examples for java.security Principal getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.jboss.dashboard.security.PermissionDescriptor.java
public void setPrincipal(Principal prpal) { principalClass = null;//w ww . j a v a 2s . co m principalName = null; if (prpal != null) { principalClass = prpal.getClass().getName(); principalName = prpal.getName(); } }
From source file:org.jboss.dashboard.security.PermissionManager.java
/** * Find the permission descriptor for given principal and permission *//*from www . j a va2 s . c om*/ public PermissionDescriptor find(final Principal prpal, final Permission perm) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(1); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer(); buf.append( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); if (prpal != null) { buf.append(" and item.principalClass = :principalClass "); buf.append(" and item.principalName = :principalName "); } buf.append( "and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource"); Query query = session.createQuery(buf.toString()); if (prpal != null) { query.setString("principalClass", prpal.getClass().getName()); query.setString("principalName", prpal.getName()); } query.setString("permissionClass", perm.getClass().getName()); query.setString("permissionResource", perm.getName()); query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); if (!results.isEmpty()) return results.get(0); else return null; } catch (Exception e) { log.error("Error retrieving PermissionDescriptor", e); return null; } }
From source file:org.josso.gl2.agent.jaas.CatalinaJAASRealm.java
/** * Construct and return a java.security.Principal instance * representing the authenticated user for the specified Subject. If no * such Principal can be constructed, return null. * * The Principal constructed is *not* GenericPrincipal as in Catalina JAASRealm class, * but CatalinaSSOUser which is a SSOUser. * The Partner Application can access SSOUser-specific properties that are not available * in GenericPrincipal.//from w ww. ja va 2 s .c o m * The JAASRealm superclass invokes this factory method to build the Catalina-specific * Principal from the Subject filled by the configured JAASLoginModule. * * @param subject The Subject representing the logged in user */ @Override protected Principal createPrincipal(String username, Subject subject) { // We also populate roles map ... CatalinaSSOUser p = CatalinaSSOUser.newInstance(this, subject); if (requiresRoleMap) { // This is a Tomcat 5.0.30 ... ! try { List<Principal> roles = new ArrayList<Principal>(); Iterator principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal principal = (Principal) principals.next(); String principalClass = principal.getClass().getName(); if (getRoleClassNames().contains(principalClass)) { log.debug("Adding role : " + principal.getName()); roles.add(principal); } // Same as Jboss - that's a pretty clean solution if ((principal instanceof Group) && "Roles".equals(principal.getName())) { Group grp = (Group) principal; Enumeration en = grp.members(); while (en.hasMoreElements()) { Principal roleP = (Principal) en.nextElement(); log.debug("Adding role : " + roleP.getName()); roles.add(roleP); } } } // Only in Catalina 5.0.30! log.debug("Storing roles in parent roleMap"); Map m = (Map) getRoleMapField().get(this); m.put(p, roles); } catch (Exception e) { log.warn(e.getMessage(), e); return p; } } return p; }
From source file:org.josso.gl2.agent.jaas.CatalinaSSOUser.java
/** * Construct and return a java.security.Principal instance * representing the authenticated user for the specified Subject. If no * such Principal can be constructed, return null. * * The Principal constructed is *not* GenericPrincipal as in Catalina JAASRealm class, * but CatalinaSSOUser which is a SSOUser. * The Partner Application can access SSOUser-specific properties that are not available * in GenericPrincipal.// w w w .jav a2 s. c o m * The JAASRealm superclass invokes this factory method to build the Catalina-specific * Principal from the Subject filled by the configured JAASLoginModule. * * @param subject The Subject representing the logged in user */ public static CatalinaSSOUser newInstance(Realm realm, Subject subject) { // Prepare to scan the Principals for this Subject String password = null; // Will not be carried forward ArrayList roles = new ArrayList(); SSOUser ssoUser = null; String username = null; // Scan the Principals for this Subject Iterator principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal principal = (Principal) principals.next(); // No need to look further - that's our own stuff if (principal instanceof CatalinaSSOUser) { if (logger.isDebugEnabled()) logger.debug("Found old CatalinaSSOUser Principal " + principal); return (CatalinaSSOUser) principal; } String principalClass = principal.getClass().getName(); if (logger.isDebugEnabled()) logger.debug("Principal: " + principalClass + " " + principal); if (_userClasses.contains(principalClass)) { // Override the default - which is the original user, accepted by // the friendly LoginManager username = principal.getName(); } if (_roleClasses.contains(principalClass)) { roles.add(principal.getName()); } // Same as Jboss - that's a pretty clean solution if ((principal instanceof Group) && "Roles".equals(principal.getName())) { Group grp = (Group) principal; Enumeration en = grp.members(); while (en.hasMoreElements()) { Principal roleP = (Principal) en.nextElement(); roles.add(roleP.getName()); } } // Save the SSOUser principal so that it can be included in the // CatalinaSSOUser Principal if (principal instanceof SSOUser) { ssoUser = (SSOUser) principal; } } if (ssoUser == null) { logger.error("Fatal: Subject does not contain an SSOUser Principal"); return null; } // Create the resulting Principal for our authenticated user if (username != null) { return (new CatalinaSSOUser(ssoUser, realm, username, password, roles)); } else { return (null); } }
From source file:org.josso.jb5.agent.CatalinaSSOUser.java
/** * Construct and return a java.security.Principal instance * representing the authenticated user for the specified Subject. If no * such Principal can be constructed, return null. * * The Principal constructed is *not* GenericPrincipal as in Catalina JAASRealm class, * but CatalinaSSOUser which is a SSOUser. * The Partner Application can access SSOUser-specific properties that are not available * in GenericPrincipal./*w ww .j a va 2 s .c o m*/ * The JAASRealm superclass invokes this factory method to build the Catalina-specific * Principal from the Subject filled by the configured JAASLoginModule. * * @param subject The Subject representing the logged in user */ public static CatalinaSSOUser newInstance(Realm realm, Subject subject) { // Prepare to scan the Principals for this Subject String password = null; // Will not be carried forward ArrayList roles = new ArrayList(); SSOUser ssoUser = null; String username = null; // Scan the Principals for this Subject Iterator principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal principal = (Principal) principals.next(); // No need to look further - that's our own stuff if (principal instanceof CatalinaSSOUser) { if (logger.isDebugEnabled()) logger.debug("Found old CatalinaSSOUser Principal " + principal); return (CatalinaSSOUser) principal; } String principalClass = principal.getClass().getName(); if (logger.isDebugEnabled()) logger.debug("Principal: " + principalClass + " " + principal); if (_userClasses.contains(principalClass)) { // Override the default - which is the original user, accepted by // the friendly LoginManager username = principal.getName(); } if (_roleClasses.contains(principalClass)) { roles.add(principal.getName()); } // Same as Jboss - that's a pretty clean solution if ((principal instanceof Group) && "Roles".equals(principal.getName())) { Group grp = (Group) principal; Enumeration en = grp.members(); while (en.hasMoreElements()) { Principal roleP = (Principal) en.nextElement(); roles.add(roleP.getName()); } } // Save the SSOUser principal so that it can be included in the // CatalinaSSOUser Principal if (principal instanceof SSOUser) { ssoUser = (SSOUser) principal; } } if (ssoUser == null) { logger.error("Fatal: Subject does not contain an SSOUser Principal"); return null; } // Create the resulting Principal for our authenticated user if (username != null) { return (new CatalinaSSOUser(ssoUser, realm, username, password, roles)); } else { return (null); } }
From source file:org.josso.tc50.agent.CatalinaNativeRealm.java
/** * Construct and return a java.security.Principal instance * representing the authenticated user for the specified Subject. If no * such Principal can be constructed, return null. *// ww w .j a v a 2s .c o m * The Principal constructed is CatalinaSSOUser which is a SSOUser. * The Partner Application can access SSOUser-specific properties that are not available * in GenericPrincipal. * * @param subject The Subject representing the logged in user */ protected Principal createPrincipal(String username, Subject subject) { CatalinaSSOUser p = CatalinaSSOUser.newInstance(this, subject); if (requiresRoleMap) { // This is a Tomcat 5.0.30 ... ! try { List<Principal> roles = new ArrayList<Principal>(); Iterator principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal principal = (Principal) principals.next(); String principalClass = principal.getClass().getName(); if (_roleClasses.contains(principalClass)) { log.debug("Adding role : " + principal.getName()); roles.add(principal); } // Same as Jboss - that's a pretty clean solution if ((principal instanceof Group) && "Roles".equals(principal.getName())) { Group grp = (Group) principal; Enumeration en = grp.members(); while (en.hasMoreElements()) { Principal roleP = (Principal) en.nextElement(); log.debug("Adding role : " + roleP.getName()); roles.add(roleP); } } } // Only in Catalina 5.0.30! log.debug("Storing roles in parent roleMap"); Map m = (Map) getRoleMapField().get(this); m.put(p, roles); } catch (Exception e) { log.warn(e.getMessage(), e); return p; } } return p; }
From source file:org.josso.tc50.agent.jaas.CatalinaJAASRealm.java
/** * Construct and return a java.security.Principal instance * representing the authenticated user for the specified Subject. If no * such Principal can be constructed, return null. * * The Principal constructed is *not* GenericPrincipal as in Catalina JAASRealm class, * but CatalinaSSOUser which is a SSOUser. * The Partner Application can access SSOUser-specific properties that are not available * in GenericPrincipal./*from www.j a v a 2 s.c o m*/ * The JAASRealm superclass invokes this factory method to build the Catalina-specific * Principal from the Subject filled by the configured JAASLoginModule. * * @param subject The Subject representing the logged in user */ protected Principal createPrincipal(String username, Subject subject) { // We also populate roles map ... CatalinaSSOUser p = CatalinaSSOUser.newInstance(this, subject); if (requiresRoleMap) { // This is a Tomcat 5.0.30 ... ! try { List<Principal> roles = new ArrayList<Principal>(); Iterator principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal principal = (Principal) principals.next(); String principalClass = principal.getClass().getName(); if (getRoleClassNames().contains(principalClass)) { log.debug("Adding role : " + principal.getName()); roles.add(principal); } // Same as Jboss - that's a pretty clean solution if ((principal instanceof Group) && "Roles".equals(principal.getName())) { Group grp = (Group) principal; Enumeration en = grp.members(); while (en.hasMoreElements()) { Principal roleP = (Principal) en.nextElement(); log.debug("Adding role : " + roleP.getName()); roles.add(roleP); } } } // Only in Catalina 5.0.30! log.debug("Storing roles in parent roleMap"); Map m = (Map) getRoleMapField().get(this); m.put(p, roles); } catch (Exception e) { log.warn(e.getMessage(), e); return p; } } return p; }
From source file:org.liveSense.service.securityManager.SecurityManagerServiceImpl.java
/** {@inheritDoc} */ private String getAuthorizableItemPath(Principal principal) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { //should check if principal implements ItemBasedPrincipal, but it is not visible here so use reflection instead Method method = principal.getClass().getMethod("getPath"); String path = (String) method.invoke(principal); return path;/*from w w w. j a v a2 s .c om*/ }
From source file:org.nuxeo.ecm.core.api.CoreInstance.java
protected static NuxeoPrincipal getPrincipal(String username) { if (username != null) { if (SYSTEM_USERNAME.equals(username)) { return new SystemPrincipal(null); } else {//from w w w. j a v a 2 s . c o m return new UserPrincipal(username, new ArrayList<String>(), false, false); } } else { LoginStack.Entry entry = ClientLoginModule.getCurrentLogin(); if (entry != null) { Principal p = entry.getPrincipal(); if (p instanceof NuxeoPrincipal) { return (NuxeoPrincipal) p; } else if (LoginComponent.isSystemLogin(p)) { return new SystemPrincipal(p.getName()); } else { throw new RuntimeException("Unsupported principal: " + p.getClass()); } } else { if (Framework.isTestModeSet()) { return new SystemPrincipal(null); } else { throw new NuxeoException( "Cannot create a CoreSession outside a security context, " + " login() missing."); } } } }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileAclDao.java
protected RepositoryFileAce toAce(final Session session, final AccessControlEntry acEntry) throws RepositoryException { Principal principal = acEntry.getPrincipal(); RepositoryFileSid sid = null;//from w w w .java2 s . co m String name = principal.getName(); DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper( session); if (principal instanceof Group) { sid = new RepositoryFileSid(JcrTenantUtils.getRoleNameUtils().getPrincipleName(name), RepositoryFileSid.Type.ROLE); } else { sid = new RepositoryFileSid(JcrTenantUtils.getUserNameUtils().getPrincipleName(name), RepositoryFileSid.Type.USER); } logger.debug(String.format("principal class [%s]", principal.getClass().getName())); //$NON-NLS-1$ Privilege[] privileges = acEntry.getPrivileges(); return new RepositoryFileAce(sid, permissionConversionHelper.privilegesToPentahoPermissions(session, privileges)); }