List of usage examples for org.springframework.security.web.authentication.preauth PreAuthenticatedAuthenticationToken PreAuthenticatedAuthenticationToken
public PreAuthenticatedAuthenticationToken(Object aPrincipal, Object aCredentials)
From source file:io.syndesis.rest.v1.handler.user.UserHandlerTest.java
@Test public void successfulWhoAmI() { openShiftServer.expect().get().withPath("/oapi/v1/users/~").andReturn(200, new UserBuilder().withFullName("Test User").withNewMetadata().withName("testuser").and().build()) .once();/*from w w w .java 2 s.c om*/ SecurityContextHolder.getContext() .setAuthentication(new PreAuthenticatedAuthenticationToken("testuser", "doesn'tmatter")); UserHandler userHandler = new UserHandler(null, new OpenShiftServiceImpl(openShiftServer.getOpenshiftClient(), null)); User user = userHandler.whoAmI(); Assertions.assertThat(user).isNotNull(); Assertions.assertThat(user.getUsername()).isEqualTo("testuser"); Assertions.assertThat(user.getFullName()).isNotEmpty().hasValue("Test User"); }
From source file:com.devicehive.websockets.WebSocketAuthenticationManager.java
public HiveAuthentication authenticateJWT(String token, HiveAuthentication.HiveAuthDetails details) { PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(token, null);// w w w .j a v a2 s . co m HiveAuthentication authentication = (HiveAuthentication) authenticationManager .authenticate(authenticationToken); authentication.setDetails(details); return authentication; }
From source file:io.syndesis.rest.v1.handler.user.UserHandlerTest.java
@Test public void successfulWhoAmIWithoutFullName() { openShiftServer.expect().get().withPath("/oapi/v1/users/~") .andReturn(200, new UserBuilder().withNewMetadata().withName("testuser").and().build()).once(); SecurityContextHolder.getContext()//from w ww .j av a2s .c o m .setAuthentication(new PreAuthenticatedAuthenticationToken("testuser", "doesn'tmatter")); UserHandler userHandler = new UserHandler(null, new OpenShiftServiceImpl(openShiftServer.getOpenshiftClient(), null)); User user = userHandler.whoAmI(); Assertions.assertThat(user).isNotNull(); Assertions.assertThat(user.getUsername()).isEqualTo("testuser"); Assertions.assertThat(user.getFullName()).isEmpty(); }
From source file:org.joyrest.oauth2.interceptor.AuthenticationInterceptor.java
private Optional<Authentication> extractToken(InternalRequest<Object> req) { return extractHeaderToken(req).filter(Objects::isNull) .flatMap(value -> req.getQueryParam(OAuth2AccessToken.ACCESS_TOKEN)).filter(Objects::nonNull) .map(token -> new PreAuthenticatedAuthenticationToken(token, "")); }
From source file:de.punyco.thirtytwosquare.auth.GoogleUserAuthenticationTest.java
@Test public void newUserShouldHaveOnlyRolesUserAndUnregistered() { testHelper.setEnvIsLoggedIn(true);/*from w w w. ja v a 2 s . c o m*/ testHelper.setEnvEmail("neverseen@gmail.com"); // Given an authentication token of a never seen before user PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken( UserServiceFactory.getUserService().getCurrentUser(), DUMMY_CREDENTIALS); // ... retrieving the user details ... UserDetails userDetails = userDetailsService.loadUserDetails(authenticationToken); // .. should yield _only_ roles USER and UNREGISTERED Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) userDetails.getAuthorities(); assertThat(authorities, hasItems(sameAsRole(Roles.USER), sameAsRole(Roles.UNREGISTERED))); }
From source file:org.openinfinity.sso.common.ss.sp.filters.OAuthAuthenticationFilter.java
@Override public void authenticate(MuleEvent event) throws org.mule.api.security.SecurityException, UnknownAuthenticationTypeException, CryptoFailureException, SecurityProviderNotFoundException, EncryptionStrategyNotFoundException, InitialisationException { LOG.debug("Authenticating Mule Event by OAuth 2"); String accessToken = accessTokenFrom(event); PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(accessToken, "N/A"); Authentication authResult = authenticate(event, authRequest); createSecurityContextToEventWithAuthResult(event, authResult); }
From source file:org.appverse.web.framework.backend.security.authentication.userpassword.managers.UserAndPasswordAuthenticationManagerImpl.java
/** * TODO: Review this method that can be used with PreAuthentication as the *//*from www . ja va2 s . com*/ @Override public void authenticatePrincipal(String principal, List<String> credentials) { List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(); User user = new User(principal, "", true, true, true, true, authList); Authentication authentication = new PreAuthenticatedAuthenticationToken(user, credentials); authenticationManager.authenticate(authentication); }
From source file:org.appverse.web.framework.backend.api.services.presentation.impl.live.AuthenticationServiceFacadeImpl.java
@Override public void authenticatePrincipal(String principal, List<String> credentials) { List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(); User user = new User(principal, "", true, true, true, true, authList); Authentication authentication = new PreAuthenticatedAuthenticationToken(user, credentials); authenticationManager.authenticate(authentication); }
From source file:com.cedac.security.acls.mongo.MongoMutableAclServiceTests.java
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Mongo mongo = embeddedMongoDbRule.getDatabaseOperation().connectionManager(); final AclCache aclCache = new SpringCacheBasedAclCache(new NoOpCacheManager().getCache("acl"), pgs, aas); fixture = new MongoMutableAclService(mongo, "test", aclCache, pgs, aas); fixture.afterPropertiesSet();// w w w . j av a 2 s . co m SecurityContextHolder.getContext() .setAuthentication(new PreAuthenticatedAuthenticationToken("admin@cedac.com", "password")); }
From source file:de.punyco.thirtytwosquare.auth.GoogleUserAuthenticationTest.java
@Test public void returningUserShouldNotHaveRoleUnregistered() { setupReturningUser();//from w w w .ja v a2 s. c om testHelper.setEnvIsLoggedIn(true); testHelper.setEnvEmail("returning@gmail.com"); // Given an authentication token of a returning user PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken( UserServiceFactory.getUserService().getCurrentUser(), DUMMY_CREDENTIALS); // ... retrieving the user details ... UserDetails userDetails = userDetailsService.loadUserDetails(authenticationToken); // ... should yield _no_ UNREGISTERED role Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) userDetails.getAuthorities(); assertThat(authorities, not(hasItem(sameAsRole(Roles.UNREGISTERED)))); }