javax.security.enterprise.CallerPrincipal Java Examples
The following examples show how to use
javax.security.enterprise.CallerPrincipal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserIdentityStore.java From javaee8-cookbook with Apache License 2.0 | 6 votes |
public CredentialValidationResult validate(UsernamePasswordCredential usernamePasswordCredential) { if (usernamePasswordCredential.getCaller().equals(Roles.ADMIN) && usernamePasswordCredential.getPassword().compareTo("1234")) { return new CredentialValidationResult( new CallerPrincipal(usernamePasswordCredential.getCaller()), new HashSet<>(Arrays.asList(Roles.ADMIN))); } else if (usernamePasswordCredential.getCaller().equals(Roles.USER) && usernamePasswordCredential.getPassword().compareTo("1234")) { return new CredentialValidationResult( new CallerPrincipal(usernamePasswordCredential.getCaller()), new HashSet<>(Arrays.asList(Roles.USER))); } return CredentialValidationResult.INVALID_RESULT; }
Example #2
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 6 votes |
private CredentialValidationResult(Status status, String storeId, CallerPrincipal callerPrincipal, String callerDn, String callerUniqueId, Set<String> groups) { if (status != VALID && (storeId != null || callerPrincipal != null || callerDn != null || callerUniqueId != null || groups != null)) { throw new IllegalArgumentException("Bad status"); } if (status == VALID && (callerPrincipal == null || callerPrincipal.getName().trim().isEmpty())) { throw new IllegalArgumentException("Null or empty CallerPrincipal"); } this.status = status; this.storeId = storeId; this.callerPrincipal = callerPrincipal; this.callerDn = callerDn; this.callerUniqueId = callerUniqueId; this.groups = groups != null ? unmodifiableSet(new HashSet<>(groups)) : emptySet(); }
Example #3
Source File: InMemoryIdentityStore.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
public CredentialValidationResult validate(UsernamePasswordCredential usernamePasswordCredential) { Credential credential = CALLER_TO_CREDENTIALS.get(usernamePasswordCredential.getCaller()); if (credential != null && usernamePasswordCredential.getPassword().compareTo(credential.getPassword())) { return new CredentialValidationResult( new CallerPrincipal(credential.getCallerName()), new HashSet<>(credential.getGroups()) ); } return INVALID_RESULT; }
Example #4
Source File: RememberMeInterceptor.java From tomee with Apache License 2.0 | 5 votes |
private AuthenticationStatus validateRequest(final InvocationContext invocationContext) throws Exception { final HttpMessageContext httpMessageContext = (HttpMessageContext) invocationContext.getParameters()[2]; final RememberMe rememberMe = getRememberMe(); final Optional<Cookie> cookie = getCookie(httpMessageContext.getRequest(), rememberMe.cookieName()); if (cookie.isPresent()) { final RememberMeCredential rememberMeCredential = new RememberMeCredential(cookie.get().getValue()); final CredentialValidationResult validate = rememberMeIdentityStore.get().validate(rememberMeCredential); if (VALID.equals(validate.getStatus())) { return httpMessageContext.notifyContainerAboutLogin(validate); } else { cookie.get().setMaxAge(0); httpMessageContext.getResponse().addCookie(cookie.get()); } } final AuthenticationStatus status = (AuthenticationStatus) invocationContext.proceed(); if (SUCCESS.equals(status) && rememberMe.isRememberMe()) { final CallerPrincipal principal = new CallerPrincipal(httpMessageContext.getCallerPrincipal().getName()); final Set<String> groups = httpMessageContext.getGroups(); final String loginToken = rememberMeIdentityStore.get().generateLoginToken(principal, groups); final Cookie rememberMeCookie = new Cookie(rememberMe.cookieName(), loginToken); rememberMeCookie.setMaxAge(rememberMe.cookieMaxAgeSeconds()); rememberMeCookie.setHttpOnly(rememberMe.cookieHttpOnly()); rememberMeCookie.setSecure(rememberMe.cookieSecureOnly()); httpMessageContext.getResponse().addCookie(rememberMeCookie); } return status; }
Example #5
Source File: CustomRememberMeIdentityStore.java From javaee8-jsf-sample with GNU General Public License v3.0 | 4 votes |
@Override public CredentialValidationResult validate(RememberMeCredential credential) { return users.findByLoginToken(credential.getToken(), REMEMBER_ME) .map(u -> new CredentialValidationResult(new CallerPrincipal(u.getUsername()), u.getRoles())) .orElse(INVALID_RESULT); }
Example #6
Source File: CustomRememberMeIdentityStore.java From javaee8-jsf-sample with GNU General Public License v3.0 | 4 votes |
@Override public String generateLoginToken(CallerPrincipal callerPrincipal, Set<String> groups) { return userService.generate(callerPrincipal.getName(), request.getRemoteAddr(), getDescription(), REMEMBER_ME); }
Example #7
Source File: JwtRememberMeIdentityStore.java From javaee8-jaxrs-sample with GNU General Public License v3.0 | 4 votes |
@Override public String generateLoginToken(CallerPrincipal callerPrincipal, Set<String> groups) { return tokenProvider.createToken(callerPrincipal.getName(), groups, true); }
Example #8
Source File: TomEEHttpMessageContext.java From tomee with Apache License 2.0 | 4 votes |
@Override public AuthenticationStatus notifyContainerAboutLogin(final String callername, final Set<String> groups) { return notifyContainerAboutLogin(new CallerPrincipal(callername), groups); }
Example #9
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(String callerName) { this(new CallerPrincipal(callerName), null); }
Example #10
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(CallerPrincipal callerPrincipal) { this(callerPrincipal, null); }
Example #11
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(String callerName, Set<String> groups) { this(new CallerPrincipal(callerName), groups); }
Example #12
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(CallerPrincipal callerPrincipal, Set<String> groups) { this(null, callerPrincipal, null, null, groups); }
Example #13
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(String storeId, String callerName, String callerDn, String callerUniqueId, Set<String> groups) { this(storeId, new CallerPrincipal(callerName), callerDn, callerUniqueId, groups); }
Example #14
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CredentialValidationResult(String storeId, CallerPrincipal callerPrincipal, String callerDn, String callerUniqueId, Set<String> groups) { this(VALID, storeId, callerPrincipal, callerDn, callerUniqueId, groups); }
Example #15
Source File: CredentialValidationResult.java From tomee with Apache License 2.0 | 4 votes |
public CallerPrincipal getCallerPrincipal() { return callerPrincipal; }
Example #16
Source File: RememberMeIdentityStore.java From tomee with Apache License 2.0 | votes |
String generateLoginToken(CallerPrincipal callerPrincipal, Set<String> groups);