com.textrecruit.ustackserverapi.auth.PermissionAuthorization Maven / Gradle / Ivy
package com.textrecruit.ustackserverapi.auth;
import java.util.ArrayList;
import java.util.List;
import com.textrecruit.ustackserverapi.params.types.ParameterDefinitionInt;
import com.textrecruit.ustack.aaa.Authorization;
import com.textrecruit.ustack.aaa.UStackPermissionEnum;
import com.textrecruit.ustack.data.UserAccount;
import com.textrecruit.ustack.exceptions.AuthorizationException;
import com.textrecruit.ustackserverapi.APIException;
import com.textrecruit.ustackserverapi.CallParameters;
import com.textrecruit.ustackserverapi.MethodDefinition;
public class PermissionAuthorization implements AuthorizationInt {
private static final PermissionAuthorization singleton = new PermissionAuthorization();
/**
* No extra parameters required
*/
public List> getAuthenticationParameters() {
List> ret = new ArrayList>();
return ret;
}
public static PermissionAuthorization getInstance() {
return singleton;
}
/**
* Ensures the caller has access to the requested account
*
* @param callParams
* @throws Exception
*/
public void authorize(MethodDefinition method, CallParameters callParams) throws APIException
{
UserAccount user = callParams.getAuthInfo(AuthTypes.AccessTokenAuth);
String resource = (String)method.getData("Resource");
UStackPermissionEnum permission = (UStackPermissionEnum)method.getData("Permission");
try {
Authorization.authorizeUser(user, resource, null, permission);
} catch (AuthorizationException e) {
throw new APIAuthorizationException("User does not have access to resource");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy