Search in sources :

Example 6 with Pair

use of org.xdi.util.Pair in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceImpl method endSession.

private Pair<SessionState, AuthorizationGrant> endSession(String idTokenHint, String sessionState, HttpServletRequest httpRequest, HttpServletResponse httpResponse, SecurityContext sec) {
    AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByIdToken(idTokenHint);
    if (authorizationGrant == null) {
        Boolean endSessionWithAccessToken = appConfiguration.getEndSessionWithAccessToken();
        if ((endSessionWithAccessToken != null) && endSessionWithAccessToken) {
            authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(idTokenHint);
        }
    }
    SessionState ldapSessionState = removeSessionState(sessionState, httpRequest, httpResponse);
    if ((authorizationGrant == null) && (ldapSessionState == null)) {
        log.info("Failed to find out authorization grant for id_token_hint '{}' and session_state '{}'", idTokenHint, sessionState);
        errorResponseFactory.throwUnauthorizedException(EndSessionErrorResponseType.INVALID_GRANT);
    }
    boolean isExternalLogoutPresent;
    boolean externalLogoutResult = false;
    isExternalLogoutPresent = externalApplicationSessionService.isEnabled();
    if (isExternalLogoutPresent && (ldapSessionState != null)) {
        String userName = ldapSessionState.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
        externalLogoutResult = externalApplicationSessionService.executeExternalEndSessionMethods(httpRequest, ldapSessionState);
        log.info("End session result for '{}': '{}'", userName, "logout", externalLogoutResult);
    }
    boolean isGrantAndExternalLogoutSuccessful = isExternalLogoutPresent && externalLogoutResult;
    if (isExternalLogoutPresent && !isGrantAndExternalLogoutSuccessful) {
        errorResponseFactory.throwUnauthorizedException(EndSessionErrorResponseType.INVALID_GRANT);
    }
    if (ldapSessionState != null) {
        grantService.removeAllTokensBySession(ldapSessionState.getDn());
    }
    if (identity != null) {
        identity.logout();
    }
    return new Pair<SessionState, AuthorizationGrant>(ldapSessionState, authorizationGrant);
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) Pair(org.xdi.util.Pair)

Example 7 with Pair

use of org.xdi.util.Pair in project oxTrust by GluuFederation.

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<Response, String>(response, idCreated);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Example 8 with Pair

use of org.xdi.util.Pair in project oxCore by GluuFederation.

the class LdapOperationsServiceImpl method populateAttributeDataTypesMapping.

private void populateAttributeDataTypesMapping(String schemaEntryDn) {
    try {
        if (ATTRIBUTE_DATA_TYPES.size() == 0) {
            // schemaEntryDn="ou=schema";
            SearchResultEntry entry = lookup(schemaEntryDn, "attributeTypes");
            Attribute attrAttributeTypes = entry.getAttribute("attributeTypes");
            Map<String, Pair<String, String>> tmpMap = new HashMap<String, Pair<String, String>>();
            for (String strAttributeType : attrAttributeTypes.getValues()) {
                AttributeTypeDefinition attrTypeDef = new AttributeTypeDefinition(strAttributeType);
                String[] names = attrTypeDef.getNames();
                if (names != null) {
                    for (String name : names) {
                        tmpMap.put(name, new Pair<String, String>(attrTypeDef.getBaseSyntaxOID(), attrTypeDef.getSuperiorType()));
                    }
                }
            }
            // Fill missing values
            for (String name : tmpMap.keySet()) {
                Pair<String, String> currPair = tmpMap.get(name);
                String sup = currPair.getSecond();
                if (currPair.getFirst() == null && sup != null) {
                    // No OID syntax?
                    // Try to lookup superior type
                    Pair<String, String> pair = tmpMap.get(sup);
                    if (pair != null) {
                        currPair.setFirst(pair.getFirst());
                    }
                }
            }
            // Populate map of attribute names vs. Java classes
            for (String name : tmpMap.keySet()) {
                String syntaxOID = tmpMap.get(name).getFirst();
                if (syntaxOID != null) {
                    Class<?> cls = OID_SYNTAX_CLASS_MAPPING.get(syntaxOID);
                    if (cls != null) {
                        ATTRIBUTE_DATA_TYPES.put(name, cls);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) Attribute(com.unboundid.ldap.sdk.Attribute) HashMap(java.util.HashMap) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) InvalidSimplePageControlException(org.gluu.persist.ldap.exception.InvalidSimplePageControlException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchException(org.gluu.persist.exception.operation.SearchException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) MappingException(org.gluu.persist.exception.mapping.MappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Pair(org.xdi.util.Pair)

Aggregations

Pair (org.xdi.util.Pair)8 Response (javax.ws.rs.core.Response)4 HttpResponse (org.apache.http.HttpResponse)2 RptIntrospectionResponse (org.xdi.oxauth.model.uma.RptIntrospectionResponse)2 UmaPermission (org.xdi.oxauth.model.uma.UmaPermission)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 JsonNode (org.codehaus.jackson.JsonNode)1 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)1 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)1 BulkResponse (org.gluu.oxtrust.model.scim2.bulk.BulkResponse)1 FidoDeviceResource (org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource)1