Skip to content

Commit

Permalink
Added UserFacade methods for session API in xsk
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Nenchovski <[email protected]>
  • Loading branch information
BorisNen authored and delchev committed May 27, 2021
1 parent a381886 commit a739a9b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class UserFacade implements IScriptingFacade {
private static final Logger logger = LoggerFactory.getLogger(UserFacade.class);

private static final String GUEST = "guest";
private static final String AUTH = "authorization";

/**
* Gets the user name.
Expand Down Expand Up @@ -123,7 +124,7 @@ public static final String getName(HttpServletRequest request) {
}
return getName();
}

/**
* Gets the user name by a given request as parameter.
*
Expand All @@ -146,12 +147,44 @@ public static final String getName(Session session) {
return getName();
}

public static final Integer getTimeout() {
if (HttpSessionFacade.isValid()) {
return HttpSessionFacade.getMaxInactiveInterval();
} else {
logger.error("Error while retrieving timeout: Session is not valid!");
}
return 0;
}

public static String getAuthType() {
if (HttpSessionFacade.isValid()) {
return HttpRequestFacade.getAuthType();
} else {
logger.error("Error while retrieving auth type: Session is not valid!");
}
return null;
}

/**
* The Authorization header return the type + token.
* Substring from the empty space to only get the token.
*/
public static String getSecurityToken() {
if (HttpSessionFacade.isValid()) {
String token = HttpRequestFacade.getHeader(AUTH);
return token.substring(token.indexOf(" "));
} else {
logger.error("Error while retrieving security token: Session is not valid!");
}
return "";
}

private static String getContextProperty(String property) throws ContextException {
if (HttpSessionFacade.isValid()) {
return HttpSessionFacade.getAttribute(property);
} else if (ThreadContextFacade.isValid()) {
Object value = ThreadContextFacade.get(property);
if ((value != null) && (value instanceof String)) {
if ((value != null) && (value instanceof String)) {
return (String) value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
/**
* API v4 User
*
*
* Note: This module is supported only with the Mozilla Rhino engine
*/

Expand All @@ -21,4 +21,16 @@ exports.getName = function() {

exports.isInRole = function(role) {
return org.eclipse.dirigible.api.v3.security.UserFacade.isInRole(role);
};

exports.getTimeout = function() {
return org.eclipse.dirigible.api.v3.security.UserFacade.getTimeout();
};

exports.getAuthType = function() {
return org.eclipse.dirigible.api.v3.security.UserFacade.getAuthType();
};

exports.getSecurityToken = function() {
return org.eclipse.dirigible.api.v3.security.UserFacade.getSecurityToken();
};

0 comments on commit a739a9b

Please sign in to comment.