Search in sources :

Example 36 with JpaRole

use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.

the class ConfigurableLoginHandler method existingUserLogin.

/**
 * Handle an existing user login.
 *
 * @param id
 *          The identity of the user, ideally the Shibboleth persistent unique identifier
 * @param request
 *          The request, for accessing any other Shibboleth variables
 */
@Override
public void existingUserLogin(String id, HttpServletRequest request) {
    Organization organization = securityService.getOrganization();
    // Load the user reference
    JpaUserReference userReference = userReferenceProvider.findUserReference(id, organization.getId());
    if (userReference == null) {
        throw new IllegalStateException("User reference '" + id + "' was not found");
    }
    // Update the reference
    userReference.setName(extractName(request));
    userReference.setEmail(extractEmail(request));
    userReference.setLastLogin(new Date());
    Set<JpaRole> roles = extractRoles(id, request);
    userReference.setRoles(roles);
    logger.debug("Shibboleth user '{}' logged in", id);
    userReferenceProvider.updateUserReference(userReference);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JpaUserReference(org.opencastproject.security.impl.jpa.JpaUserReference) Date(java.util.Date)

Example 37 with JpaRole

use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.

the class ConfigurableLoginHandler method extractRoles.

/**
 * Extracts the roles from the request.
 *
 * @param request
 *          the request
 * @return the roles
 */
private Set<JpaRole> extractRoles(String id, HttpServletRequest request) {
    JpaOrganization organization = fromOrganization(securityService.getOrganization());
    Set<JpaRole> roles = new HashSet<JpaRole>();
    roles.add(new JpaRole(roleFederationMember, organization));
    roles.add(new JpaRole(roleUserPrefix + id, organization));
    roles.add(new JpaRole(organization.getAnonymousRole(), organization));
    if (headerHomeOrganization != null) {
        String homeOrganization = request.getHeader(headerHomeOrganization);
        roles.add(new JpaRole(roleOrganizationPrefix + homeOrganization + roleOrganizationSuffix, organization));
    }
    if (StringUtils.equals(id, bootstrapUserId)) {
        roles.add(new JpaRole(GLOBAL_ADMIN_ROLE, organization));
    }
    return roles;
}
Also used : JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) HashSet(java.util.HashSet)

Aggregations

JpaRole (org.opencastproject.security.impl.jpa.JpaRole)37 HashSet (java.util.HashSet)18 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)18 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)18 Test (org.junit.Test)16 JpaOrganization (org.opencastproject.security.impl.jpa.JpaOrganization)14 JpaGroup (org.opencastproject.security.impl.jpa.JpaGroup)12 NotFoundException (org.opencastproject.util.NotFoundException)11 Role (org.opencastproject.security.api.Role)9 Path (javax.ws.rs.Path)6 RestQuery (org.opencastproject.util.doc.rest.RestQuery)6 EntityManager (javax.persistence.EntityManager)5 EntityTransaction (javax.persistence.EntityTransaction)4 Group (org.opencastproject.security.api.Group)4 SecurityService (org.opencastproject.security.api.SecurityService)4 User (org.opencastproject.security.api.User)4 Date (java.util.Date)3 POST (javax.ws.rs.POST)3 PUT (javax.ws.rs.PUT)3 JSONArray (org.json.simple.JSONArray)3