use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class CramMD5MechanismHandler method getUserPassword.
private static String getUserPassword(String userName) {
try {
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
AMIdentityRepository idRepo = new AMIdentityRepository(adminToken, SMSEntry.getRootSuffix());
IdSearchControl searchControl = new IdSearchControl();
searchControl.setTimeOut(0);
searchControl.setMaxResults(0);
searchControl.setAllReturnAttributes(false);
IdSearchResults searchResults = idRepo.searchIdentities(IdType.USER, userName, searchControl);
Set users = searchResults.getSearchResults();
if (users == null || users.isEmpty()) {
if (debug.messageEnabled()) {
debug.message("CramMD5MechanismHandler.getUserPassword: " + "no user found");
}
return null;
}
if (users.size() > 1) {
if (debug.messageEnabled()) {
debug.message("CramMD5MechanismHandler.getUserPassword: " + "more than 1 user found");
}
return null;
}
AMIdentity user = (AMIdentity) users.iterator().next();
Set passwords = user.getAttribute("userPassword");
if (passwords == null || passwords.isEmpty()) {
if (debug.messageEnabled()) {
debug.message("CramMD5MechanismHandler.getUserPassword: " + "user has no password");
}
return null;
}
if (passwords.size() > 1) {
if (debug.messageEnabled()) {
debug.message("CramMD5MechanismHandler.getUserPassword: " + "user has more than 1 passwords");
}
return null;
}
String password = (String) passwords.iterator().next();
if (password.startsWith("{CLEAR}")) {
password = password.substring(7);
}
return password;
} catch (Exception ex) {
AuthnSvcUtils.debug.error("CramMD5MechanismHandler.getUserPassword: ", ex);
return null;
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class WSSReplayPasswd method onLoginSuccess.
/**
* Post processing on successful authentication.
* @param requestParamsMap contains HttpServletRequest parameters
* @param request HttpServlet request
* @param response HttpServlet response
* @param ssoToken user's session
* @throws AuthenticationException if there is an error while setting
* the session paswword property
*/
public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
try {
if (!useHashedPassword) {
String userpasswd = request.getParameter(PASSWORD_TOKEN);
if (userpasswd != null) {
ssoToken.setProperty("EncryptedUserPassword", Crypt.encrypt(userpasswd));
}
} else {
String userName = ssoToken.getPrincipal().getName();
String universalID = ssoToken.getProperty("sun.am.UniversalIdentifier");
if (debug.messageEnabled()) {
debug.message("WSSReplayPassword:Authenticated user : " + userName);
debug.message("WSSReplayPassword:Authenticated UUID : " + universalID);
}
AMIdentity amId = new AMIdentity(getAdminToken(), universalID);
Set tmp = amId.getAttribute("userPassword");
if (tmp != null && !tmp.isEmpty()) {
String userPassword = (String) tmp.iterator().next();
ssoToken.setProperty("HashedUserPassword", userPassword);
}
}
} catch (SSOException sse) {
debug.warning("WSSReplayPasswd.onLoginSuccess: " + "sso exception", sse);
} catch (IdRepoException ire) {
if (debug.warningEnabled()) {
debug.warning("WSSReplayPassword.onLoginSuccess: ", ire);
}
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class TokenResource method deleteToken.
/**
* Deletes the token with the provided token id.
*
* @param context The context.
* @param tokenId The token id.
* @param deleteRefreshToken Whether to delete associated refresh token, if token id is for an access token.
* @return {@code Void} if the token has been deleted.
*/
private Promise<Void, ResourceException> deleteToken(Context context, String tokenId, boolean deleteRefreshToken) {
try {
AMIdentity uid = getUid(context);
JsonValue token = tokenStore.read(tokenId);
if (token == null) {
if (debug.errorEnabled()) {
debug.error("TokenResource :: DELETE : No token with ID, " + tokenId + " found to delete");
}
throw new NotFoundException("Token Not Found", null);
}
String username = getAttributeValue(token, USERNAME);
if (username == null || username.isEmpty()) {
if (debug.errorEnabled()) {
debug.error("TokenResource :: DELETE : No username associated with " + "token with ID, " + tokenId + ".");
}
throw new PermanentException(HttpURLConnection.HTTP_NOT_FOUND, "Not Found", null);
}
String grantType = getAttributeValue(token, GRANT_TYPE);
if (grantType != null && grantType.equalsIgnoreCase(CLIENT_CREDENTIALS)) {
if (deleteRefreshToken) {
deleteAccessTokensRefreshToken(token);
}
tokenStore.delete(tokenId);
} else {
String realm = getAttributeValue(token, REALM);
AMIdentity uid2 = identityManager.getResourceOwnerIdentity(username, realm);
if (uid.equals(uid2) || uid.equals(adminUserId)) {
if (deleteRefreshToken) {
deleteAccessTokensRefreshToken(token);
}
tokenStore.delete(tokenId);
} else {
if (debug.errorEnabled()) {
debug.error("TokenResource :: DELETE : Only the resource owner or an administrator may perform " + "a delete on the token with ID, " + tokenId + ".");
}
throw new PermanentException(401, "Unauthorized", null);
}
}
return newResultPromise(null);
} catch (CoreTokenException e) {
return new ServiceUnavailableException(e.getMessage(), e).asPromise();
} catch (ResourceException e) {
return e.asPromise();
} catch (SSOException e) {
debug.error("TokenResource :: DELETE : Unable to retrieve identity of the requesting user. Unauthorized.");
return new PermanentException(401, "Unauthorized", e).asPromise();
} catch (IdRepoException e) {
debug.error("TokenResource :: DELETE : Unable to retrieve identity of the requesting user. Unauthorized.");
return new PermanentException(401, "Unauthorized", e).asPromise();
} catch (UnauthorizedClientException e) {
debug.error("TokenResource :: DELETE : Requesting user is unauthorized.");
return new PermanentException(401, "Unauthorized", e).asPromise();
}
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class AuditHistory method queryCollection.
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
AMIdentity identity = getIdentity(context);
Set<UmaAuditEntry> history;
try {
if (request.getQueryFilter().toString().equals("true")) {
history = auditLogger.getEntireHistory(identity);
} else {
history = auditLogger.getHistory(identity, request);
}
} catch (ServerException e) {
return new InternalServerErrorException(e).asPromise();
}
List<ResourceResponse> results = new ArrayList<>();
for (UmaAuditEntry entry : history) {
JsonValue result = entry.asJson();
results.add(newResourceResponse(entry.getId(), String.valueOf(result.hashCode()), result));
}
QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
return QueryResponsePresentation.perform(handler, request, results);
}
use of com.sun.identity.idm.AMIdentity in project OpenAM by OpenRock.
the class ResourceSetService method createSubject.
protected Subject createSubject(String username, String realm) {
AMIdentity identity = coreWrapper.getIdentity(username, realm);
JwtPrincipal principal = new JwtPrincipal(json(object(field("sub", identity.getUniversalId()))));
Set<Principal> principals = new HashSet<>();
principals.add(principal);
return new Subject(false, principals, Collections.emptySet(), Collections.emptySet());
}
Aggregations