Compare commits

...

7 Commits

Author SHA1 Message Date
Lucio Lelii bca36f2d64 Update 'README.md' 2023-07-05 10:43:56 +02:00
Roberto Cirillo 53d7393d2a Update 'CHANGELOG.md'
fix changelog changing the introduction position
2020-07-07 10:02:57 +02:00
Lucio Lelii 3cf3505e6a commit to solve buil dissue on release 4.24 2020-06-22 16:49:16 +02:00
Lucio Lelii 0e2a8dfbed commit for release 2.24 2020-06-22 15:47:34 +02:00
lucio d6b6d4135e log for testing removed 2020-04-07 19:15:33 +02:00
lucio d0a7c0520a solved a bug with scope maps 2020-04-07 19:14:43 +02:00
lucio f62a477b84 returning scopeMaps on token resolution 2020-04-07 17:55:15 +02:00
9 changed files with 81 additions and 54 deletions

View File

@ -27,7 +27,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

View File

@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8

8
CHANGELOG.md Normal file
View File

@ -0,0 +1,8 @@
# Changelog for "auhtorization-service"
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## \[v2.1.3] [r4.24.0] - 2020-06-22
### Fixes
- bug on ApiKey Management (https://support.d4science.org/issues/19487)

View File

@ -1,6 +1,6 @@
# Authorization service # Authorization service
StorageHub implements the gCube Workspace feature Implements the gCube Authorization feature
## Structure of the project ## Structure of the project

View File

@ -15,7 +15,7 @@
<includes> <includes>
<include>README.md</include> <include>README.md</include>
<include>LICENSE.md</include> <include>LICENSE.md</include>
<include>changelog.xml</include> <include>CHANGELOG.md</include>
<include>profile.xml</include> <include>profile.xml</include>
</includes> </includes>
<fileMode>755</fileMode> <fileMode>755</fileMode>

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>authorization-service</artifactId> <artifactId>authorization-service</artifactId>
<version>2.1.1</version> <version>2.1.3</version>
<name>authorization service</name> <name>authorization service</name>
<packaging>war</packaging> <packaging>war</packaging>
@ -61,7 +61,6 @@
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId> <artifactId>common-scope</artifactId>

View File

@ -7,7 +7,6 @@ import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application; import javax.ws.rs.core.Application;
import org.gcube.common.authorizationservice.configuration.AuthorizationConfiguration; import org.gcube.common.authorizationservice.configuration.AuthorizationConfiguration;
import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("/gcube/service/*") @ApplicationPath("/gcube/service/*")
public class AuthorizationService extends Application { public class AuthorizationService extends Application {
@ -22,6 +21,7 @@ public class AuthorizationService extends Application {
classes.add(KeyRetriever.class); classes.add(KeyRetriever.class);
classes.add(PolicyManager.class); classes.add(PolicyManager.class);
classes.add(TokenManager.class); classes.add(TokenManager.class);
classes.add(ApiKeyManager.class);
return classes; return classes;
} }

View File

@ -60,8 +60,15 @@ public class TokenManager {
CalledMethodProvider.instance.set("retrieve"); CalledMethodProvider.instance.set("retrieve");
log.info("token retreiver called with token {}",token); log.info("token retreiver called with token {}",token);
AuthorizationEntry info = persistence.getAuthorizationEntry(token); AuthorizationEntry info = null;
try {
info = persistence.getAuthorizationEntry(token);
} catch ( Throwable t) {
log.error("erorr on authorization", t);
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("error on authorization").type(MediaType.TEXT_PLAIN).build());
}
log.info("info retrieved {}",info); log.info("info retrieved {}",info);
if (info == null){ if (info == null){
@ -69,25 +76,21 @@ public class TokenManager {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("token "+token+" not found").type(MediaType.TEXT_PLAIN).build()); .entity("token "+token+" not found").type(MediaType.TEXT_PLAIN).build());
} }
/* /*
try{ try{
ScopeProvider.instance.set(info.getContext()); ScopeProvider.instance.set(info.getContext());
ServiceMap map = ServiceMap.instance; ServiceMap map = ((ScopedServiceMap)ServiceMap.instance).currentMap();
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
info.setMap(map); info.setMap(map);
}catch(Exception e){ }catch(Throwable e){
log.error("error retrieving map for {}", info.getContext(), e); log.error("error retrieving map for {}", info.getContext(), e);
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Error retrieving map").type(MediaType.TEXT_PLAIN).build());
}*/ }*/
log.debug("returning info {}", info); log.debug("returning info {}", info);
return info; return info;
} }
/** /**
* *
* retrieves the AuthorzationEntry connected to the specified token * retrieves the AuthorzationEntry connected to the specified token
@ -100,14 +103,26 @@ public class TokenManager {
@Produces(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML)
public AuthorizationEntryList retrieveTokenBunch(@NotNull @QueryParam("token") List<String> tokens ) { public AuthorizationEntryList retrieveTokenBunch(@NotNull @QueryParam("token") List<String> tokens ) {
CalledMethodProvider.instance.set("retrieve"); CalledMethodProvider.instance.set("retrieve");
log.info("token retreiver called with tokens {}",tokens); log.info("token retreiver in bunch called with tokens {}",tokens);
List<AuthorizationEntry> toReturn = new ArrayList<AuthorizationEntry>(); List<AuthorizationEntry> toReturn = new ArrayList<AuthorizationEntry>();
for (String token : tokens ) { for (String token : tokens ) {
try { try {
AuthorizationEntry info = persistence.getAuthorizationEntry(token); AuthorizationEntry info = persistence.getAuthorizationEntry(token);
/*
try{
ScopeProvider.instance.set(info.getContext());
DefaultServiceMap map = (DefaultServiceMap)((ScopedServiceMap)ServiceMap.instance).currentMap();
ScopeProvider.instance.reset();
info.setMap(map);
}catch(Throwable e){
log.error("error retrieving map for {}", info.getContext(), e);
}
*/
toReturn.add(info); toReturn.add(info);
}catch(Exception e) {} }catch(Exception t) {
log.error("erorr on authorization", t);
}
} }
log.info("info retrieved {}",toReturn); log.info("info retrieved {}",toReturn);
@ -116,13 +131,13 @@ public class TokenManager {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("no tokens poassed have been found ").type(MediaType.TEXT_PLAIN).build()); .entity("no tokens poassed have been found ").type(MediaType.TEXT_PLAIN).build());
} }
return new AuthorizationEntryList(toReturn); return new AuthorizationEntryList(toReturn);
} }
/** /**
* *
* retrieves the AuthorzationEntry connected to the specified token * retrieves the AuthorzationEntry connected to the specified token
@ -135,16 +150,16 @@ public class TokenManager {
public String getTokenByUserAndContext(@NotNull @PathParam("user") String user, @QueryParam("context") String context ) { public String getTokenByUserAndContext(@NotNull @PathParam("user") String user, @QueryParam("context") String context ) {
CalledMethodProvider.instance.set("retrieve"); CalledMethodProvider.instance.set("retrieve");
log.info("resolving token for user {} in context {}",user, context); log.info("resolving token for user {} in context {}",user, context);
if (context==null){ if (context==null){
log.error("null context found"); log.error("null context found");
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
.entity("null context found").type(MediaType.TEXT_PLAIN).build()); .entity("null context found").type(MediaType.TEXT_PLAIN).build());
} }
String token = persistence.getExistingToken(user, context, Constants.DEFAULT_TOKEN_QUALIFIER); String token = persistence.getExistingToken(user, context, Constants.DEFAULT_TOKEN_QUALIFIER);
if (token == null){ if (token == null){
log.error("token {} not found ", token); log.error("token {} not found ", token);
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
@ -165,7 +180,7 @@ public class TokenManager {
return token; return token;
} }
/** /**
* *
* Generates a token for a user (saving the passed roles) if it doesn't exist yet. * Generates a token for a user (saving the passed roles) if it doesn't exist yet.
@ -200,7 +215,7 @@ public class TokenManager {
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build()); .entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
} }
} }
/** /**
* *
* Generates a token for a user (saving the passed roles) if it doesn't exist yet. * Generates a token for a user (saving the passed roles) if it doesn't exist yet.
@ -228,8 +243,8 @@ public class TokenManager {
.entity("Error setting roles to token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build()); .entity("Error setting roles to token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
} }
} }
/** /**
* *
* REmoves a token for a user. * REmoves a token for a user.
@ -251,14 +266,14 @@ public class TokenManager {
if (clientId.split(":").length>1) throw new Exception("invalid user id: "+clientId); if (clientId.split(":").length>1) throw new Exception("invalid user id: "+clientId);
persistence.removeAllAuthorizationsEntryForClientId(context, clientId); persistence.removeAllAuthorizationsEntryForClientId(context, clientId);
}catch(Exception e){ }catch(Exception e){
log.error("error generating token ",e); log.error("error generating token ",e);
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity("Error removing Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build()); .entity("Error removing Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
} }
} }
/** /**
* *
* Generates a token for a service if it doesn't exist yet. * Generates a token for a service if it doesn't exist yet.
@ -302,25 +317,25 @@ public class TokenManager {
CalledMethodProvider.instance.set("generate"); CalledMethodProvider.instance.set("generate");
log.info("calling generate service token bunch"); log.info("calling generate service token bunch");
try{ try{
AuthorizationEntry callerInfo = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE); AuthorizationEntry callerInfo = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
List<String> tokensToReturn = new ArrayList<String>(); List<String> tokensToReturn = new ArrayList<String>();
for (String token: entity.getContainerTokens()) { for (String token: entity.getContainerTokens()) {
AuthorizationEntry authInfo = this.retrieveToken(token); AuthorizationEntry authInfo = this.retrieveToken(token);
if (authInfo==null) continue; if (authInfo==null) continue;
if (!authInfo.getClientInfo().getId().equals(callerInfo.getClientInfo().getId())) if (!authInfo.getClientInfo().getId().equals(callerInfo.getClientInfo().getId()))
log.warn("a token with a different ContainerInfo of the caller used, skipping it"); log.warn("a token with a different ContainerInfo of the caller used, skipping it");
else { else {
String genToken = generateTokenForServiceInfo(entity.getInfo(), authInfo); String genToken = generateTokenForServiceInfo(entity.getInfo(), authInfo);
tokensToReturn.add(genToken); tokensToReturn.add(genToken);
} }
} }
return new ListMapper(tokensToReturn); return new ListMapper(tokensToReturn);
}catch(Exception e){ }catch(Exception e){
log.error("error generating tokens ",e); log.error("error generating tokens ",e);
@ -385,7 +400,7 @@ public class TokenManager {
.entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build()); .entity("Error Generating Token: "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
} }
} }
@Path("node") @Path("node")
@PUT @PUT
@Consumes(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_XML)
@ -393,16 +408,16 @@ public class TokenManager {
@Context HttpServletRequest req) { @Context HttpServletRequest req) {
CalledMethodProvider.instance.set("generate"); CalledMethodProvider.instance.set("generate");
try{ try{
AuthorizationEntry info = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE); AuthorizationEntry info = (AuthorizationEntry)req.getAttribute(AuthorizedCallFilter.AUTH_ATTRIBUTE);
if (context!=null) if (context!=null)
return generateTokenForContainerInfo(containerInfo, context); return generateTokenForContainerInfo(containerInfo, context);
else if (info!=null){ else if (info!=null){
log.info("generator called for node {} in context {} ",containerInfo.getId(), info.getContext()); log.info("generator called for node {} in context {} ",containerInfo.getId(), info.getContext());
return generateTokenForContainerInfo(containerInfo, info); return generateTokenForContainerInfo(containerInfo, info);
} }
throw new Exception("error trying to activate node (token and context are empty)"); throw new Exception("error trying to activate node (token and context are empty)");
}catch(Exception e){ }catch(Exception e){
log.error("error generating token ",e); log.error("error generating token ",e);
@ -423,7 +438,7 @@ public class TokenManager {
} }
return token; return token;
} }
private String generateTokenForContainerInfo(ContainerInfo containerInfo, AuthorizationEntry authInfo) throws Exception{ private String generateTokenForContainerInfo(ContainerInfo containerInfo, AuthorizationEntry authInfo) throws Exception{
if (containerInfo.getId().split(":").length!=2) throw new Exception("invalid container id: "+containerInfo.getId()); if (containerInfo.getId().split(":").length!=2) throw new Exception("invalid container id: "+containerInfo.getId());
@ -436,7 +451,7 @@ public class TokenManager {
} }
return token; return token;
} }
private String generateTokenForServiceInfo(ServiceInfo serviceInfo, AuthorizationEntry authInfo) throws Exception{ private String generateTokenForServiceInfo(ServiceInfo serviceInfo, AuthorizationEntry authInfo) throws Exception{
if (serviceInfo.getId().split(":").length!=3) throw new Exception("invalid service id: "+serviceInfo.getId()); if (serviceInfo.getId().split(":").length!=3) throw new Exception("invalid service id: "+serviceInfo.getId());

View File

@ -16,9 +16,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult; import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistence;
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.CalledMethodProvider; import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.authorizationservice.configuration.AllowedEntity; import org.gcube.common.authorizationservice.configuration.AllowedEntity;
@ -26,9 +23,6 @@ import org.gcube.common.authorizationservice.configuration.AuthorizationConfigur
import org.gcube.common.authorizationservice.configuration.AuthorizationRule; import org.gcube.common.authorizationservice.configuration.AuthorizationRule;
import org.gcube.common.authorizationservice.configuration.ConfigurationHolder; import org.gcube.common.authorizationservice.configuration.ConfigurationHolder;
import org.gcube.common.authorizationservice.util.TokenPersistence; import org.gcube.common.authorizationservice.util.TokenPersistence;
import org.gcube.common.scope.api.ScopeProvider;
import org.jboss.weld.context.ApplicationContext;
import org.omg.PortableInterceptor.SUCCESSFUL;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -51,7 +45,8 @@ public class AuthorizedCallFilter implements Filter {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { FilterChain chain) throws IOException, ServletException {
String token = request.getParameter(TOKEN_HEADER)==null?((HttpServletRequest)request).getHeader(TOKEN_HEADER): String token = request.getParameter(TOKEN_HEADER)==null?((HttpServletRequest)request).getHeader(TOKEN_HEADER):
request.getParameter(TOKEN_HEADER); request.getParameter(TOKEN_HEADER);
@ -82,15 +77,20 @@ public class AuthorizedCallFilter implements Filter {
pathInfo = servletPath.replace("/gcube/service", ""); pathInfo = servletPath.replace("/gcube/service", "");
log.info("called path info {} ", pathInfo); log.info("called path info {} ", pathInfo);
if (pathInfo==null || pathInfo.isEmpty()){ if (pathInfo==null || pathInfo.isEmpty()){
log.info("call rejected from filters: invalid path"); ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
log.error("call rejected from filters: invalid path");
generateAccounting("Unknown", "Unknown", callerIp, false, startTime, request.getLocalName());
return; return;
} }
} }
if (requiresToken(pathInfo) && token==null ){ if (requiresToken(pathInfo) && token==null ){
((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED); ((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
log.info("call rejected from filters, call requires caller token"); log.error("call rejected from filters, call requires caller token");
generateAccounting("Unknown", "Unknown", callerIp, false, startTime, request.getLocalName());
return; return;
} }
@ -107,13 +107,15 @@ public class AuthorizedCallFilter implements Filter {
if (!checkAllowed(pathInfo, callerIp, info)){ if (!checkAllowed(pathInfo, callerIp, info)){
((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED); ((HttpServletResponse)response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
log.info("call rejected from filters"); log.error("call rejected from filters");
generateAccounting("Unknown", "Unknown", callerIp, false, startTime, request.getLocalName());
return; return;
} }
chain.doFilter(request, response); chain.doFilter(request, response);
generateAccounting("Unknown", "Unknown", callerIp, true, startTime, request.getLocalName());
//generateAccounting("Unknown", "Unknown", callerIp, true, startTime, request.getLocalName());
} }
private boolean requiresToken(String pathInfo) { private boolean requiresToken(String pathInfo) {
@ -188,7 +190,7 @@ public class AuthorizedCallFilter implements Filter {
public void destroy() {} public void destroy() {}
void generateAccounting(String caller, String callerQualifier, String remoteHost, boolean success, long startTime, String host){ void generateAccounting(String caller, String callerQualifier, String remoteHost, boolean success, long startTime, String host){
AuthorizationConfiguration conf = ConfigurationHolder.getConfiguration(); /*AuthorizationConfiguration conf = ConfigurationHolder.getConfiguration();
AccountingPersistenceFactory.setFallbackLocation(conf.getAccountingDir()); AccountingPersistenceFactory.setFallbackLocation(conf.getAccountingDir());
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence(); AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord(); ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
@ -210,6 +212,8 @@ public class AuthorizedCallFilter implements Filter {
}catch(Exception ex){ }catch(Exception ex){
log.warn("invalid record passed to accounting ",ex); log.warn("invalid record passed to accounting ",ex);
} }
*/
log.info("REQUEST SERVED for method {} in {} ms with result {}", CalledMethodProvider.instance.get(), System.currentTimeMillis()-startTime, success?OperationResult.SUCCESS:OperationResult.FAILED);
} }
} }