com.textrecruit.ustackserverapi.auth.UserNamePasswordAuth Maven / Gradle / Ivy
package com.textrecruit.ustackserverapi.auth;
import java.util.ArrayList;
import java.util.List;
import com.textrecruit.ustackserverapi.params.ParamNames;
import com.textrecruit.ustackserverapi.params.types.ParameterDefinitionInt;
import org.jboss.netty.handler.codec.http.HttpRequest;
import com.textrecruit.ustack.aaa.Authentication;
import com.textrecruit.ustack.aaa.Authorization;
import com.textrecruit.ustack.data.UserAccount;
import com.textrecruit.ustack.exceptions.AuthenticationException;
import com.textrecruit.ustack.exceptions.AuthorizationException;
import com.textrecruit.ustackserverapi.APIException;
import com.textrecruit.ustackserverapi.CallParameters;
import com.textrecruit.ustackserverapi.MethodDefinition;
/**
* Authentication method for username/password combo in HTTP request params
*
* @author jdanner
*
*/
public class UserNamePasswordAuth implements AuthenticationInt {
public String getAuthenticationDescription() {
return "Username and password combo (in request parameters) required.";
}
public boolean isBasicAuth() {
return false;
}
public List> getAuthenticationParameters() {
List> ret = new ArrayList>();
ret.add(ParamNames.username);
ret.add(ParamNames.password);
return ret;
}
@Override
public UserAccount authenticate(MethodDefinition method, HttpRequest req, CallParameters params) throws APIException {
UserAccount user = null;
try {
user = Authentication.authenticateUser(params.get(ParamNames.username), params.get(ParamNames.password));
} catch (AuthenticationException e) {
throw new APIAuthenticationException(e.getMessage());
}
if (method.getAuthenticationGroup() != null)
{
try {
Authorization.authorizeUser(user, "*", null, method.getAuthenticationGroup());
} catch (AuthorizationException e) {
throw new APIAuthorizationException("Not Authorized");
}
}
return user;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy