Tabnine Logo
UserSession.getUser
Code IndexAdd Tabnine to your IDE (free)

How to use
getUser
method
in
com.oberasoftware.jasdb.api.security.UserSession

Best Java code snippets using com.oberasoftware.jasdb.api.security.UserSession.getUser (Showing top 8 results out of 315)

origin: oberasoftware/jasdb

private boolean checkGrantHierarchy(String objectName, UserSession userSession, AccessMode objectMode) throws JasDBStorageException {
  String userName = userSession.getUser().getUsername();
  LOG.debug("Checking grant hierarchy for: {} for user: {}", objectName, userName);
  //check root read access
  StringBuilder currentPath = new StringBuilder();
  currentPath.append(Constants.OBJECT_SEPARATOR);
  AccessMode grantedMode = getGrantedMode(currentPath.toString(), userSession);
  LOG.debug("Root access mode: {} for user: {}", grantedMode, userName);
  grantedMode = grantedMode == null ? AccessMode.NONE : grantedMode;
  String[] pathElements = objectName.replaceFirst(Constants.OBJECT_SEPARATOR, "").split(Constants.OBJECT_SEPARATOR);
  for(String pathElement : pathElements) {
    currentPath.append(pathElement);
    AccessMode mode = getGrantedMode(currentPath.toString(), userSession);
    if(mode != null) {
      grantedMode = mode;
      if(mode == AccessMode.NONE) {
        break;
      }
    }
    currentPath.append(Constants.OBJECT_SEPARATOR);
  }
  LOG.debug("Grant level: {} for path: {}", grantedMode, currentPath.toString());
  boolean granted = grantedMode != null ? grantedMode.getRank() >= objectMode.getRank() : false;
  return granted;
}
origin: oberasoftware/jasdb

private AccessMode getGrantedMode(String objectName, UserSession userSession) throws JasDBStorageException {
  StatRecord getGrantRecord = StatisticsMonitor.createRecord("auth:grant:check");
  try {
    String username = userSession.getUser().getUsername();
    if(cachedGrants.containsKey(objectName)) {
      return verifyGrantMode(cachedGrants.get(objectName), username);
    } else {
      GrantObject objectGrantObject = getMutableGrantObject(userSession, objectName);
      if(objectGrantObject != null) {
        cachedGrants.put(objectName, objectGrantObject);
        return verifyGrantMode(objectGrantObject, username);
      } else {
        return null;
      }
    }
  } finally {
    getGrantRecord.stop();
  }
}
origin: oberasoftware/jasdb

private void checkToken(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws IOException, ServletException {
  try {
    String token = httpServletRequest.getHeader("oauth_token");
    String sessionId = httpServletRequest.getHeader("sessionid");
    LOG.debug("Token: {} for session: {}", token, sessionId);
    if(StringUtils.stringNotEmpty(token) && StringUtils.stringNotEmpty(sessionId)) {
      UserSession session = sessionManager.getSession(sessionId);
      if(session != null) {
        CryptoEngine cryptoEngine = CryptoFactory.getEngine();
        String expectedTokenHash = cryptoEngine.hash(sessionId, token);
        if (expectedTokenHash.equals(session.getAccessToken())) {
          httpServletRequest.setAttribute("session", new UserSessionImpl(sessionId, token, session.getEncryptedContentKey(), session.getUser()));
          filterChain.doFilter(httpServletRequest, httpServletResponse);
        } else {
          handleErrorResponse(httpServletResponse, UNAUTHORIZED_CODE, "Invalid token");
        }
      } else {
        handleErrorResponse(httpServletResponse, UNAUTHORIZED_CODE, "Invalid token");
      }
    } else {
      handleErrorResponse(httpServletResponse, UNAUTHORIZED_CODE, "No token");
    }
  } catch(JasDBStorageException e) {
    LOG.error("Unknown error happened when processing token", e);
    handleErrorResponse(httpServletResponse, 500, "Unknown error");
  }
}
origin: oberasoftware/jasdb

@Override
public void authorize(UserSession userSession, String object, AccessMode mode) throws JasDBStorageException {
  StatRecord authRecord = StatisticsMonitor.createRecord("auth:object");
  try {
    if(userSession != null) {
      String userName = userSession.getUser().getUsername();
      boolean granted = checkGrantHierarchy(object, userSession, mode);
      LOG.debug("User: {} is privileged: {} on object: {}", userName, granted, object);
      if(!granted) {
        throw new JasDBSecurityException("User: " + userName + " has insufficient privileges on object: " + object);
      }
    } else {
      throw new JasDBSecurityException("Unable to authorize user, no session");
    }
  } finally {
    authRecord.stop();
  }
}
origin: oberasoftware/jasdb

public SecureUserSession(UserSession userSession) {
  this.sessionId = userSession.getSessionId();
  this.user = userSession.getUser();
  this.encryptedContentKey = userSession.getEncryptedContentKey();
  try {
    CryptoEngine cryptoEngine = CryptoFactory.getEngine();
    accessTokenHash = cryptoEngine.hash(sessionId, userSession.getAccessToken());
  } catch(JasDBSecurityException e) {
    throw new RuntimeJasDBException("Unable to hash token", e);
  }
}
origin: oberasoftware/jasdb

@Override
public User addUser(UserSession currentSession, String userName, String allowedHost, String password) throws JasDBStorageException {
  authorize(currentSession, "/Users", AccessMode.WRITE);
  User currentUser = currentSession.getUser();
  CryptoEngine cryptoEngine = CryptoFactory.getEngine();
  String contentKey = cryptoEngine.decrypt(currentUser.getPasswordSalt(), currentSession.getAccessToken(), currentSession.getEncryptedContentKey());
  return credentialsProvider.addUser(userName, allowedHost, contentKey, password);
}
origin: oberasoftware/jasdb

private GrantObject decrypt(UserSession session, EncryptedGrants encryptedGrants) throws JasDBStorageException {
  CryptoEngine contentCryptoEngine = CryptoFactory.getEngine();
  String contentKey = contentCryptoEngine.decrypt(session.getUser().getPasswordSalt(), session.getAccessToken(), session.getEncryptedContentKey());
  CryptoEngine cryptoEngine = CryptoFactory.getEngine(encryptedGrants.getEncryptionEngine());
  String decryptedData = cryptoEngine.decrypt(encryptedGrants.getSalt(), contentKey, encryptedGrants.getEncryptedData());
  return GrantObjectMeta.fromEntity(SimpleEntity.fromJson(decryptedData));
}
origin: oberasoftware/jasdb

private EncryptedGrants encryptGrants(GrantObject grantObject, UserSession userSession) throws JasDBStorageException {
  CryptoEngine cryptoEngine = CryptoFactory.getEngine();
  String contentKey = CryptoFactory.getEngine().decrypt(userSession.getUser().getPasswordSalt(), userSession.getAccessToken(), userSession.getEncryptedContentKey());
  String salt = cryptoEngine.generateSalt();
  String unencryptedData = SimpleEntity.toJson(GrantObjectMeta.toEntity(grantObject));
  String encryptedData = cryptoEngine.encrypt(salt, contentKey, unencryptedData);
  return new EncryptedGrants(grantObject.getObjectName(), encryptedData, salt, cryptoEngine.getDescriptor());
}
com.oberasoftware.jasdb.api.securityUserSessiongetUser

Popular methods of UserSession

  • getSessionId
  • getAccessToken
  • getEncryptedContentKey

Popular in Java

  • Finding current android device location
  • getContentResolver (Context)
  • runOnUiThread (Activity)
  • compareTo (BigDecimal)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now