Package org.apache.geronimo.security

Examples of org.apache.geronimo.security.GeronimoSecurityException


        if (defaultPrincipal == null) {
            AutoMapAssistant config = securityConfig.getAssistant();
            try {
                if (config != null) {
                    Set assistants = kernel.listGBeans(new ObjectName("geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm()));
                    if (assistants.size() < 1 || assistants.size() > 1) throw new GeronimoSecurityException("Only one auto mapping assistant should match " + config.getSecurityRealm());

                    org.apache.geronimo.security.realm.AutoMapAssistant assistant = (org.apache.geronimo.security.realm.AutoMapAssistant) assistants.iterator().next();
                    org.apache.geronimo.security.deploy.Principal principal = assistant.obtainDefaultPrincipal();
                    defaultPrincipal = new DefaultPrincipal();
                    defaultPrincipal.setPrincipal(principal);
                    defaultPrincipal.setRealmName(((SecurityRealm)assistant).getRealmName());
                }
            } catch (MalformedObjectNameException e) {
                throw new GeronimoSecurityException("Bad object name geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm());
            }

        }
        if (defaultPrincipal == null) throw new GeronimoSecurityException("Unable to generate default principal");

        return generateDefaultPrincipal(securityConfig, defaultPrincipal);
    }
View Full Code Here


        JAASJettyPrincipal result = new JAASJettyPrincipal("default");
        Subject defaultSubject = new Subject();

        RealmPrincipal realmPrincipal = ConfigurationUtil.generateRealmPrincipal(defaultPrincipal.getPrincipal(), defaultPrincipal.getRealmName());
        if (realmPrincipal == null) {
            throw new GeronimoSecurityException("Unable to create realm principal");
        }
        PrimaryRealmPrincipal primaryRealmPrincipal = ConfigurationUtil.generatePrimaryRealmPrincipal(defaultPrincipal.getPrincipal(), defaultPrincipal.getRealmName());
        if (primaryRealmPrincipal == null) {
            throw new GeronimoSecurityException("Unable to create primary realm principal");
        }

        defaultSubject.getPrincipals().add(realmPrincipal);
        defaultSubject.getPrincipals().add(primaryRealmPrincipal);
View Full Code Here

                    configuration.addToRole(roleName, new WebRoleRefPermission(servletName, roleName));
                }
            }

        } catch (ClassCastException cce) {
            throw new GeronimoSecurityException("Policy configuration object does not implement RoleMappingConfiguration", cce.getCause());
        } catch (PolicyContextException e) {
            throw new GeronimoSecurityException(e);
        }
    }
View Full Code Here

        AutoMapAssistant config = security.getAssistant();
        try {
            if (config != null) {
                ObjectName assistantName = new ObjectName("geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm());
                Set assistants = context.getKernel().listGBeans(assistantName);
                if (assistants.size() < 1 || assistants.size() > 1) throw new GeronimoSecurityException("Only one auto mapping assistant should match " + assistantName);

                org.apache.geronimo.security.realm.AutoMapAssistant assistant = (org.apache.geronimo.security.realm.AutoMapAssistant) assistants.iterator().next();
                String realmName = ((SecurityRealm) assistant).getRealmName();
                Iterator principalClasses = null;
                if (config.getClassOverrides().size() > 0) {
                    principalClasses = config.getClassOverrides().iterator();
                } else {
                    principalClasses = assistant.obtainRolePrincipalClasses().iterator();
                }

                Iterator roles = securityRoles.iterator();
                while (roles.hasNext()) {
                    String roleName = (String) roles.next();
                    Set principalSet = new HashSet();
                    Subject roleDesignate = new Subject();

                    while (principalClasses.hasNext()) {
                        Principal principal = new Principal();
                        principal.setClassName((String) principalClasses.next());
                        principal.setPrincipalName(roleName);

                        RealmPrincipal realmPrincipal = ConfigurationUtil.generateRealmPrincipal(principal, realmName);
                        if (realmPrincipal == null) throw new GeronimoSecurityException("Unable to create realm principal");

                        principalSet.add(realmPrincipal);
                        roleDesignate.getPrincipals().add(realmPrincipal);
                    }
                    roleMapper.addRoleMapping(roleName, principalSet);
                    if (roleDesignate.getPrincipals().size() > 0) context.setRoleDesignate(roleName, roleDesignate);
                }
            }
        } catch (MalformedObjectNameException e) {
            throw new GeronimoSecurityException("Bad object name geronimo.security:type=SecurityRealm,realm=" + config.getSecurityRealm());
        }
    }
View Full Code Here

        while (rollMappings.hasNext()) {
            Role role = (Role) rollMappings.next();
            String roleName = role.getRoleName();
            Set principalSet = new HashSet();

            if (!securityRoles.contains(roleName)) throw new GeronimoSecurityException("Role does not exist in this configuration");

            Subject roleDesignate = new Subject();

            Iterator realms = role.getRealms().iterator();
            while (realms.hasNext()) {
                Realm realm = (Realm) realms.next();

                Iterator principals = realm.getPrincipals().iterator();
                while (principals.hasNext()) {
                    Principal principal = (Principal) principals.next();

                    RealmPrincipal realmPrincipal = ConfigurationUtil.generateRealmPrincipal(principal, realm.getRealmName());
                    if (realmPrincipal == null) throw new GeronimoSecurityException("Unable to create realm principal");

                    principalSet.add(realmPrincipal);
                    if (principal.isDesignatedRunAs()) roleDesignate.getPrincipals().add(realmPrincipal);
                }
            }
View Full Code Here

        try {
            factory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
            policyConfiguration = factory.getPolicyConfiguration(contextId, false);
        } catch (ClassNotFoundException e) {
            throw new GeronimoSecurityException("Unable to find PolicyConfigurationFactory", e);
        } catch (PolicyContextException e) {
            throw new GeronimoSecurityException("Unable to find policy configuration with that id", e);
        }
    }
View Full Code Here

     * @param role The role that is to be mapped to a set of principals.
     * @param principals The set of principals that are to be mapped to to role.
     * @throws org.apache.geronimo.security.GeronimoSecurityException if the mapping principals to the same role twice occurs.
     */
    public void addRoleMapping(String role, Collection principals) throws GeronimoSecurityException {
        if (!configured) throw new GeronimoSecurityException("Must call configure() first");

        try {
            RoleMappingConfiguration roleMapper = (RoleMappingConfiguration) policyConfiguration;

            if (!roleNames.contains(role)) throw new GeronimoSecurityException("Role does not exist in this configuration");

            roleMapper.addRoleMapping(role, principals);
        } catch (ClassCastException cce) {
            throw new GeronimoSecurityException("Policy configuration object does not implement RoleMappingConfiguration", cce.getCause());
        } catch (PolicyContextException pe) {
            throw new GeronimoSecurityException("Method addRoleMapping threw an exception", pe.getCause());
        }
    }
View Full Code Here

        PolicyConfiguration other;

        try {
            other = factory.getPolicyConfiguration(link.getContextID(), false);
        } catch (PolicyContextException e) {
            throw new GeronimoSecurityException("Unable to find policy configuration with that id", e);
        }

        if (other != null) {
            try {
                policyConfiguration.linkConfiguration(other);
            } catch (PolicyContextException e) {
                throw new GeronimoSecurityException("Unable to link configuration", e.getCause());
            }

        }
    }
View Full Code Here

     */
    public void delete() throws GeronimoSecurityException {
        try {
            policyConfiguration.delete();
        } catch (PolicyContextException e) {
            throw new GeronimoSecurityException("Unable to delete configuration", e.getCause());
        }
    }
View Full Code Here

     */
    public void commit() throws GeronimoSecurityException {
        try {
            policyConfiguration.commit();
        } catch (PolicyContextException e) {
            throw new GeronimoSecurityException("Unable to commit configuration", e.getCause());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.security.GeronimoSecurityException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.