use of org.gluu.util.Pair in project oxAuth by GluuFederation.
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, new String[] { "uid", "gluuStatus" });
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(), User.class, 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 org.gluu.util.Pair in project oxTrust by GluuFederation.
the class CacheRefreshTimer method removeTargetEntries.
private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
Date runDate = new Date(this.lastFinishedTime);
PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
List<String> result1 = new ArrayList<String>();
List<String> result2 = new ArrayList<String>();
for (GluuSimplePerson removedPerson : removedPersons) {
String inum = removedPerson.getAttribute(OxTrustConstants.inum);
// Update GluuInumMap if it exist
GluuInumMap currentInumMap = inumInumMap.get(inum);
if (currentInumMap == null) {
log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
} else {
GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
try {
inumDbPersistenceEntryManager.merge(removedInumMap);
result2.add(removedInumMap.getInum());
} catch (BasePersistenceException ex) {
log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
continue;
}
}
// Remove person from target server
try {
targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
result1.add(inum);
} catch (BasePersistenceException ex) {
log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
continue;
}
log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
}
return new Pair<List<String>, List<String>>(result1, result2);
}
use of org.gluu.util.Pair in project oxAuth by GluuFederation.
the class IntrospectionWebService method getAuthorizationGrant.
/**
* @return we return pair of authorization grant or otherwise true - if it's basic client authentication or false if it is not
* @throws UnsupportedEncodingException when encoding is not supported
*/
private Pair<AuthorizationGrant, Boolean> getAuthorizationGrant(String authorization, String accessToken) throws UnsupportedEncodingException {
AuthorizationGrant grant = tokenService.getBearerAuthorizationGrant(authorization);
if (grant != null) {
final String authorizationAccessToken = tokenService.getBearerToken(authorization);
final AbstractToken accessTokenObject = grant.getAccessToken(authorizationAccessToken);
if (accessTokenObject != null && accessTokenObject.isValid()) {
return new Pair<>(grant, false);
} else {
log.error("Access token is not valid: " + authorizationAccessToken);
return EMPTY;
}
}
grant = tokenService.getBasicAuthorizationGrant(authorization);
if (grant != null) {
return new Pair<>(grant, false);
}
if (tokenService.isBasicAuthToken(authorization)) {
String encodedCredentials = tokenService.getBasicToken(authorization);
String token = new String(Base64.decodeBase64(encodedCredentials), StandardCharsets.UTF_8);
int delim = token.indexOf(":");
if (delim != -1) {
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)) {
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 {
log.trace("Failed to perform basic authentication for client: " + clientId);
}
}
}
return EMPTY;
}
use of org.gluu.util.Pair in project oxAuth by GluuFederation.
the class RequestParameterService method getParameterValueWithType.
public Pair<String, String> getParameterValueWithType(String p_name) {
String value = null;
String clazz = null;
final Object o = identity.getWorkingParameter(p_name);
if (o instanceof String) {
final String s = (String) o;
value = s;
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<String, String>(value, clazz);
}
use of org.gluu.util.Pair in project oxAuth by GluuFederation.
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