use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class AuthContextLocal method login.
/**
* Starts the login process for the given <code>AuthContextLocal</code>s
* object for the given <code>Principal</code> and the user's password.
* This method should be called primarily
* when the authenticator knows there would no other
* credentials needed to complete the authentication process.
*
* @param principal <code>Principal</code> of the user to be authenticated.
* @param password password for the user.
* @throws AuthLoginException if an error occurred
* during login.
* @supported.api
*/
public void login(Principal principal, char[] password) throws AuthLoginException {
// Make sure principal and password are not null
if (principal == null)
throw new AuthLoginException(amAuthContextLocal, "invalid-username", null);
if (password == null)
throw new AuthLoginException(amAuthContextLocal, "invalid-password", null);
// Copy the password
this.password = password;
login(null, null, principal, password, null);
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class DefaultAccountProvider method provisionUser.
/**
* {@inheritDoc}
*/
public AMIdentity provisionUser(AMIdentityRepository idrepo, Map<String, Set<String>> attributes) throws AuthLoginException {
AMIdentity identity = null;
try {
String userId;
Set<String> idAttribute = attributes.get(idNameAttribute);
if (idAttribute != null && !idAttribute.isEmpty()) {
userId = idAttribute.iterator().next();
} else {
userId = UUID.randomUUID().toString();
}
identity = idrepo.createIdentity(IdType.USER, userId, attributes);
} catch (IdRepoException ire) {
debug.error("DefaultAccountMapper.getAccount: IRE ", ire);
debug.error("LDAPERROR Code = " + ire.getLDAPErrorCode());
if (ire.getLDAPErrorCode() != null && !ire.getLDAPErrorCode().equalsIgnoreCase("68")) {
throw new AuthLoginException("Failed to create user");
}
} catch (SSOException ex) {
debug.error("DefaultAccountMapper.getAttributes: Problem while creating the user. SSOExc", ex);
throw new AuthLoginException("Failed to create user");
}
return identity;
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class JsonAttributeMapper method getAttributes.
/**
* {@inheritDoc}
*/
public Map<String, Set<String>> getAttributes(Map<String, String> attributeMapConfiguration, String jsonText) throws AuthLoginException {
if (debug.messageEnabled()) {
debug.message("defaultAttributeMapper.getAttributes: " + attributeMapConfiguration);
}
JSONObject json;
try {
json = new JSONObject(jsonText);
} catch (JSONException ex) {
debug.error("OAuth.process(): JSONException: " + ex.getMessage());
throw new AuthLoginException(bundleName, ex.getMessage(), null);
}
Map<String, Set<String>> attr = new HashMap<String, Set<String>>();
String responseName = "";
String localName;
for (Map.Entry<String, String> entry : attributeMapConfiguration.entrySet()) {
try {
responseName = entry.getKey();
localName = entry.getValue();
if (debug.messageEnabled()) {
debug.message("defaultAttributeMapper.getAttributes: " + responseName + ":" + localName);
}
String data;
if (responseName != null && responseName.indexOf(".") != -1) {
StringTokenizer parts = new StringTokenizer(responseName, ".");
data = json.getJSONObject(parts.nextToken()).getString(parts.nextToken());
} else {
data = json.getString(responseName);
}
if (prefix != null && (prefixedAttributes.contains(localName) || prefixedAttributes.contains("*"))) {
data = prefix + data;
}
attr.put(localName, CollectionUtils.asSet(data));
} catch (JSONException ex) {
debug.error("defaultAttributeMapper.getAttributes: Could not get the attribute" + responseName, ex);
}
}
return attr;
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class Anonymous method process.
public int process(Callback[] callbacks, int state) throws AuthLoginException {
if (errorMsg != null) {
throw new AuthLoginException(amAuthAnonymous, errorMsg, null);
}
useSharedstate = isSharedStateEnabled();
try {
if (useSharedstate) {
usernameParam = (String) sharedState.get(getUserKey());
if (processAnonUser(usernameParam)) {
setAuthLevel(authLevel);
return ISAuthConstants.LOGIN_SUCCEED;
}
}
if (callbacks != null && callbacks.length > 0) {
if (callbacks[0] instanceof NameCallback) {
usernameParam = ((NameCallback) callbacks[0]).getName();
if (debug.messageEnabled()) {
debug.message("Anonymous:process received NameCallback " + usernameParam);
}
if (processAnonUser(usernameParam)) {
setAuthLevel(authLevel);
return ISAuthConstants.LOGIN_SUCCEED;
}
}
}
if (validAnonUsernames != null && !(validAnonUsernames.isEmpty())) {
usernameParam = sendCallback();
} else {
usernameParam = defaultAnonUser;
}
storeUsernamePasswd(usernameParam, null);
processAnonUser(usernameParam);
setAuthLevel(authLevel);
if (debug.messageEnabled()) {
debug.message("Set auth level: " + authLevel + "\nAnonymous userid: " + userTokenId);
}
} catch (Exception e) {
debug.error("login: User not found in valid Anon List");
setFailureID(usernameParam);
throw new AuthLoginException(amAuthAnonymous, "AnonValidateEx", null);
}
return ISAuthConstants.LOGIN_SUCCEED;
}
use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.
the class Application method authenticateToLDAP.
private ModuleState authenticateToLDAP(String userName, String userPassword) throws AuthLoginException {
if (debug.messageEnabled()) {
debug.message("In authenticateToLDAP with User : " + userName);
}
try {
if (isSuperAdmin(userName)) {
String baseDN = CollectionHelper.getServerMapAttr(currentConfig, ISAuthConstants.LDAP_BASEDN);
ldapUtil = new LDAPAuthUtils(Collections.singleton(AuthD.directoryHostName + ":" + AuthD.directoryPort), Collections.<String>emptySet(), ldapSSL, AMResourceBundleCache.getInstance().getResBundle(amAuthApplication, getLoginLocale()), baseDN, debug);
ldapUtil.authenticateUser(userName, userPassword);
if (ldapUtil.getState() == ModuleState.SUCCESS) {
userTokenId = userName;
} else {
debug.message("Invalid adminID or admin Password");
setFailureID(ldapUtil.getUserId(userName));
throw new AuthLoginException(amAuthApplication, "InvalidUP", null);
}
} else {
if (initLDAPAttributes(ISAuthConstants.LDAP_SERVICE_NAME)) {
ldapUtil.authenticateUser(userName, userPassword);
} else {
debug.message("Invalid userID or user Password");
setFailureID(userName);
throw new AuthLoginException(amAuthApplication, "basicLDAPex", null);
}
}
return ldapUtil.getState();
} catch (LDAPUtilException ex) {
setFailureID(userName);
if (ResultCode.NO_SUCH_OBJECT.equals(ex.getResultCode())) {
debug.message("The specified user does not exist.");
throw new AuthLoginException(amAuthApplication, "NoUser", null);
} else if (ResultCode.INVALID_CREDENTIALS.equals(ex.getResultCode())) {
debug.message("Invalid password.");
String failureUserID = ldapUtil.getUserId();
throw new InvalidPasswordException(amAuthApplication, "InvalidUP", null, failureUserID, ex);
} else {
throw new AuthLoginException(amAuthApplication, "basicLDAPex", null);
}
}
}
Aggregations