Search in sources :

Example 1 with AuthenticationContext

use of com.hortonworks.streamline.streams.security.AuthenticationContext in project streamline by hortonworks.

the class SecurityCatalogResource method getCurrentUser.

private User getCurrentUser(SecurityContext securityContext) {
    Principal principal = securityContext.getUserPrincipal();
    if (principal == null) {
        throw EntityNotFoundException.byMessage("No principal in security context");
    }
    String userName = SecurityUtil.getUserName(principal.getName());
    if (userName == null || userName.isEmpty()) {
        throw EntityNotFoundException.byMessage("Empty user name for principal " + principal);
    }
    User user = catalogService.getUser(userName);
    if (user == null) {
        throw EntityNotFoundException.byMessage("User '" + userName + "' is not in the user database.");
    }
    AuthenticationContext context = new AuthenticationContext();
    context.setPrincipal(principal);
    if (authorizer.hasRole(context, Roles.ROLE_ADMIN)) {
        user.setAdmin(true);
    } else {
        user.setAdmin(false);
    }
    return user;
}
Also used : User(com.hortonworks.streamline.streams.security.catalog.User) AuthenticationContext(com.hortonworks.streamline.streams.security.AuthenticationContext) Principal(java.security.Principal)

Aggregations

AuthenticationContext (com.hortonworks.streamline.streams.security.AuthenticationContext)1 User (com.hortonworks.streamline.streams.security.catalog.User)1 Principal (java.security.Principal)1