Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user session management rest API endpoint #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
</build>

<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>org.wso2.carbon.identity.user.session</artifactId>
<scope>provided</scope>
<version>${carbon.identity.user.session.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.wso2.carbon.identity.local.auth.api.endpoint;

import io.swagger.annotations.ApiParam;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.wso2.carbon.identity.local.auth.api.endpoint.dto.AllSessionsDTO;
import org.wso2.carbon.identity.local.auth.api.endpoint.factories.SessionApiServiceFactory;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

@Path("/session")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.Api(value = "/session", description = "the session API")
public class SessionApi {

private final SessionApiService delegate = SessionApiServiceFactory.getSessionApi();

@GET

@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Get active sessions", notes = "This API is used to retrieve user's session information.", response = AllSessionsDTO.class)
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successful response"),

@io.swagger.annotations.ApiResponse(code = 400, message = "Bad Request"),

@io.swagger.annotations.ApiResponse(code = 401, message = "Unauthorized"),

@io.swagger.annotations.ApiResponse(code = 404, message = "Not Found"),

@io.swagger.annotations.ApiResponse(code = 500, message = "Server Error") })

public Response getUserSession(@Context MessageContext context)
{
return delegate.getUserSession(context);
}
@DELETE
@Path("/{sessionId}")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Terminate a session", notes = "This API is used to terminate user's session.", response = void.class)
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successful response"),

@io.swagger.annotations.ApiResponse(code = 204, message = "No content"),

@io.swagger.annotations.ApiResponse(code = 400, message = "Bad Request"),

@io.swagger.annotations.ApiResponse(code = 401, message = "Unauthorized"),

@io.swagger.annotations.ApiResponse(code = 500, message = "Server Error") })

public Response terminateASession(@Context MessageContext context ,@ApiParam(value = "id of the session",required=true ) @PathParam("sessionId") String sessionId)
{
return delegate.terminateASession(context, sessionId);
}
@DELETE

@Consumes({ "application/json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation(value = "Terminate all sessions", notes = "This API is used to terminate user's session.", response = void.class)
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "Successful response"),

@io.swagger.annotations.ApiResponse(code = 204, message = "No content"),

@io.swagger.annotations.ApiResponse(code = 400, message = "Bad Request"),

@io.swagger.annotations.ApiResponse(code = 401, message = "Unauthorized"),

@io.swagger.annotations.ApiResponse(code = 500, message = "Server Error") })

public Response terminateAllSessions(@Context MessageContext context)
{
return delegate.terminateAllSessions(context);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.wso2.carbon.identity.local.auth.api.endpoint;

import org.apache.cxf.jaxrs.ext.MessageContext;

import javax.ws.rs.core.Response;

public abstract class SessionApiService {
public abstract Response getUserSession(MessageContext context);
public abstract Response terminateASession(MessageContext context, String sessionId);
public abstract Response terminateAllSessions(MessageContext context);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.wso2.carbon.identity.local.auth.api.endpoint.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;





@ApiModel(description = "")
public class AllSessionsDTO {



private List<SessionDTO> sessions = new ArrayList<SessionDTO>();


/**
* Active applications in session.
**/
@ApiModelProperty(value = "Active applications in session.")
@JsonProperty("sessions")
public List<SessionDTO> getSessions() {
return sessions;
}
public void setSessions(List<SessionDTO> sessions) {
this.sessions = sessions;
}



@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AllSessionsDTO {\n");

sb.append(" sessions: ").append(sessions).append("\n");
sb.append("}\n");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.wso2.carbon.identity.local.auth.api.endpoint.dto;


import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;





@ApiModel(description = "")
public class ApplicationDTO {



private String subject = null;


private String app = null;


/**
* User name of application.
**/
@ApiModelProperty(value = "User name of application.")
@JsonProperty("subject")
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}


/**
* Name of application.
**/
@ApiModelProperty(value = "Name of application.")
@JsonProperty("app")
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app;
}



@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ApplicationDTO {\n");

sb.append(" subject: ").append(subject).append("\n");
sb.append(" app: ").append(app).append("\n");
sb.append("}\n");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.wso2.carbon.identity.local.auth.api.endpoint.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;





@ApiModel(description = "")
public class SessionDTO {



private List<ApplicationDTO> applications = new ArrayList<ApplicationDTO>();


private String userAgent = null;


private String ip = null;


private String loginTime = null;


private String lastAccessTime = null;


private String sessionId = null;


/**
* Active applications in session.
**/
@ApiModelProperty(value = "Active applications in session.")
@JsonProperty("applications")
public List<ApplicationDTO> getApplications() {
return applications;
}
public void setApplications(List<ApplicationDTO> applications) {
this.applications = applications;
}


/**
* User agent of session.
**/
@ApiModelProperty(value = "User agent of session.")
@JsonProperty("userAgent")
public String getUserAgent() {
return userAgent;
}
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}


/**
* Ip address of particular session.
**/
@ApiModelProperty(value = "Ip address of particular session.")
@JsonProperty("ip")
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}


/**
* Login time of particular session.
**/
@ApiModelProperty(value = "Login time of particular session.")
@JsonProperty("loginTime")
public String getLoginTime() {
return loginTime;
}
public void setLoginTime(String loginTime) {
this.loginTime = loginTime;
}


/**
* Last access time of particular session.
**/
@ApiModelProperty(value = "Last access time of particular session.")
@JsonProperty("lastAccessTime")
public String getLastAccessTime() {
return lastAccessTime;
}
public void setLastAccessTime(String lastAccessTime) {
this.lastAccessTime = lastAccessTime;
}


/**
* Id of particular session.
**/
@ApiModelProperty(value = "Id of particular session.")
@JsonProperty("sessionId")
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}



@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class SessionDTO {\n");

sb.append(" applications: ").append(applications).append("\n");
sb.append(" userAgent: ").append(userAgent).append("\n");
sb.append(" ip: ").append(ip).append("\n");
sb.append(" loginTime: ").append(loginTime).append("\n");
sb.append(" lastAccessTime: ").append(lastAccessTime).append("\n");
sb.append(" sessionId: ").append(sessionId).append("\n");
sb.append("}\n");
return sb.toString();
}
}
Loading