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);
}
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);
}
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);
}
}
Aggregations