Skip to content

Commit

Permalink
Authentication resource accepts GET and POST
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Jul 27, 2017
1 parent 926aefd commit f7b2318
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<properties>
<poms.version>3.1.0-SNAPSHOT</poms.version>
<seed.version>3.3.0-SNAPSHOT</seed.version>
<jjwt.version>0.7.0</jjwt.version>

<compatibility.skip>true</compatibility.skip>

Expand Down Expand Up @@ -78,6 +79,11 @@
<artifactId>seed-web-security</artifactId>
<version>${seed.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

Expand All @@ -22,18 +23,24 @@ public class AuthenticationResource {
private SecuritySupport securitySupport;

@GET
public Response authenticate() {
public Response authenticateGet() {
if (!securitySupport.isAuthenticated()) {
return Response.status(Response.Status.FORBIDDEN).build();
return Response.status(Response.Status.UNAUTHORIZED).build();
}
return Response.status(Response.Status.NO_CONTENT).build();
}

@POST
public Response authenticatePost() {
if (!securitySupport.isAuthenticated()) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
return Response.status(Response.Status.NO_CONTENT).build();
}

@DELETE
public Response deauthenticate() {
securitySupport.logout();

return Response.status(Response.Status.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AuthorizationsResource {
@Produces(MediaType.APPLICATION_JSON)
public Response getAuthenticatedSubjectAuthorizations() {
if (!securitySupport.isAuthenticated()) {
return Response.status(Response.Status.FORBIDDEN).build();
return Response.status(Response.Status.UNAUTHORIZED).build();
}

// Principals
Expand All @@ -61,9 +61,9 @@ public Response getAuthenticatedSubjectAuthorizations() {
roleRepresentation.setAttributes(roleAttributes);
roleRepresentations.add(roleRepresentation);
}

// Individual permissions
List<String[]> individualPermissions = new ArrayList<>();

AuthorizationsRepresentation authorizationsRepresentation = new AuthorizationsRepresentation();
authorizationsRepresentation.setId(securitySupport.getSimplePrincipalByName(Principals.IDENTITY).getValue());
authorizationsRepresentation.setType("user");
Expand Down

0 comments on commit f7b2318

Please sign in to comment.