use of io.jans.util.Pair in project jans by JanssenProject.
the class RequestParameterService method getParameterValueWithType.
public Pair<String, String> getParameterValueWithType(String name) {
String value = null;
String clazz = null;
final Object o = identity.getWorkingParameter(name);
if (o instanceof String) {
value = (String) o;
clazz = String.class.getName();
} else if (o instanceof Integer) {
final Integer i = (Integer) o;
value = i.toString();
clazz = Integer.class.getName();
} else if (o instanceof Boolean) {
final Boolean b = (Boolean) o;
value = b.toString();
clazz = Boolean.class.getName();
}
return new Pair<>(value, clazz);
}
use of io.jans.util.Pair in project jans by JanssenProject.
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;
}
else if (ws == fido2DeviceWS)
switch(verb) {
case PUT:
Fido2DeviceResource dev = mapper.readValue(data, Fido2DeviceResource.class);
response = fido2DeviceWS.updateF2Device(dev, fragment, "id", null);
break;
case DELETE:
response = fido2DeviceWS.deleteF2Device(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = fido2DeviceWS.patchF2Device(pr, fragment, "id", null);
break;
case POST:
response = fido2DeviceWS.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, idCreated);
}
use of io.jans.util.Pair in project jans by JanssenProject.
the class AuthenticationService method localAuthenticate.
private Pair<Boolean, User> localAuthenticate(String nameValue, String password, String... nameAttributes) {
String lowerNameValue = StringHelper.toString(nameValue);
User user = userService.getUserByAttributes(lowerNameValue, nameAttributes, "uid", "jansStatus");
if (user != null) {
if (!checkUserStatus(user)) {
return new Pair<Boolean, User>(false, user);
}
// Use local LDAP server for user authentication
boolean authenticated = ldapEntryManager.authenticate(user.getDn(), password);
if (authenticated) {
configureAuthenticatedUser(user);
updateLastLogonUserTime(user);
log.trace("Authenticate: credentials: '{}', credentials.userName: '{}', authenticatedUser.userId: '{}'", System.identityHashCode(credentials), credentials.getUsername(), getAuthenticatedUserId());
}
return new Pair<Boolean, User>(authenticated, user);
}
return new Pair<Boolean, User>(false, null);
}
use of io.jans.util.Pair in project jans by JanssenProject.
the class IntrospectionWebService method isBasicTokenValid.
private Pair<AuthorizationGrant, Boolean> isBasicTokenValid(String authorization, String accessToken) throws UnsupportedEncodingException {
String encodedCredentials = tokenService.getBasicToken(authorization);
String token = new String(Base64.decodeBase64(encodedCredentials), StandardCharsets.UTF_8);
int delim = token.indexOf(":");
if (delim == -1) {
return EMPTY;
}
String clientId = URLDecoder.decode(token.substring(0, delim), Util.UTF8_STRING_ENCODING);
String password = URLDecoder.decode(token.substring(delim + 1), Util.UTF8_STRING_ENCODING);
if (clientService.authenticate(clientId, password)) {
AuthorizationGrant grant = authorizationGrantList.getAuthorizationGrantByAccessToken(accessToken);
if (grant != null && !grant.getClientId().equals(clientId)) {
log.trace("Failed to match grant object clientId and client id provided during authentication.");
return EMPTY;
}
return new Pair<>(grant, true);
} else {
if (log.isTraceEnabled())
log.trace("Failed to perform basic authentication for client: {}", clientId);
}
return EMPTY;
}
use of io.jans.util.Pair in project jans by JanssenProject.
the class EndSessionRestWebServiceImpl method getPair.
private Pair<SessionId, AuthorizationGrant> getPair(String idTokenHint, String sid, HttpServletRequest httpRequest) {
AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByIdToken(idTokenHint);
if (authorizationGrant == null) {
Boolean endSessionWithAccessToken = appConfiguration.getEndSessionWithAccessToken();
if ((endSessionWithAccessToken != null) && endSessionWithAccessToken) {
authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(idTokenHint);
}
}
SessionId ldapSessionId = null;
try {
String id = cookieService.getSessionIdFromCookie(httpRequest);
if (StringHelper.isNotEmpty(id)) {
ldapSessionId = sessionIdService.getSessionId(id);
}
if (StringUtils.isNotBlank(sid) && ldapSessionId == null) {
ldapSessionId = sessionIdService.getSessionBySid(sid);
}
} catch (Exception e) {
log.error("Failed to current session id.", e);
}
return new Pair<>(ldapSessionId, authorizationGrant);
}
Aggregations