List of usage examples for org.springframework.security.web.authentication.www DigestAuthenticationEntryPoint setKey
public void setKey(String key)
From source file:org.vaadin.spring.samples.mvp.security.config.DigestAuthConfig.java
@Bean public DigestAuthenticationEntryPoint digestEntryPoint() { DigestAuthenticationEntryPoint digestAuthenticationEntryPoint = new DigestAuthenticationEntryPoint(); digestAuthenticationEntryPoint.setKey(env.getProperty("app.security.digest.key", DEFAULT_DIGEST_KEY)); digestAuthenticationEntryPoint/*from w w w.j av a 2s .c o m*/ .setRealmName(env.getProperty("app.security.digest.realm", DEFAULT_DIGEST_REALM)); digestAuthenticationEntryPoint.setNonceValiditySeconds( Integer.valueOf(env.getProperty("app.security.digest.validity", DEFAULT_DIGEST_NONCE_VALIDITY))); return digestAuthenticationEntryPoint; }
From source file:com.avaya.subMgmt.server.SecurityConfigAdapter.java
@Bean public DigestAuthenticationEntryPoint digestEntryPoint() { DigestAuthenticationEntryPoint digestAuthenticationEntryPoint = new DigestAuthenticationEntryPoint(); digestAuthenticationEntryPoint.setKey("mykey"); digestAuthenticationEntryPoint.setRealmName("myrealm"); return digestAuthenticationEntryPoint; }
From source file:org.opendatakit.configuration.TestDigestSecurityConfiguration.java
@Bean public DigestAuthenticationEntryPoint digestEntryPoint() throws ODKEntityNotFoundException, ODKOverQuotaException, ODKDatastoreException, PropertyVetoException { DigestAuthenticationEntryPoint entryPoint = new DigestAuthenticationEntryPoint(); entryPoint.setRealmName(testUserServiceConfiguration.realm().getRealmString()); entryPoint .setKey(ServerPreferencesPropertiesTable.getSiteKey(testUserServiceConfiguration.callingContext())); entryPoint.setNonceValiditySeconds(1800); return entryPoint; }
From source file:org.opendatakit.configuration.SecurityConfiguration.java
@Bean public DigestAuthenticationEntryPoint digestEntryPoint() throws ODKEntityNotFoundException, ODKOverQuotaException, ODKDatastoreException, PropertyVetoException { DigestAuthenticationEntryPoint entryPoint = new DigestAuthenticationEntryPoint(); entryPoint.setRealmName(userServiceConfiguration.realm().getRealmString()); entryPoint.setKey(ServerPreferencesPropertiesTable.getSiteKey(userServiceConfiguration.callingContext())); entryPoint.setNonceValiditySeconds(1800); return entryPoint; }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPointTests.java
@Test public void testDetectsMissingRealmName() throws Exception { DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint(); ep.setKey("dcdc"); ep.setNonceValiditySeconds(12);//www. j a v a2 s . c o m try { ep.afterPropertiesSet(); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).isEqualTo("realmName must be specified"); } }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPointTests.java
@Test public void testGettersSetters() { DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint(); assertThat(ep.getNonceValiditySeconds()).isEqualTo(300); // 5 mins default ep.setRealmName("realm"); assertThat(ep.getRealmName()).isEqualTo("realm"); ep.setKey("dcdc"); assertThat(ep.getKey()).isEqualTo("dcdc"); ep.setNonceValiditySeconds(12);//from www .java2 s.c o m assertThat(ep.getNonceValiditySeconds()).isEqualTo(12); }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPointTests.java
@Test public void testNormalOperation() throws Exception { DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint(); ep.setRealmName("hello"); ep.setKey("key"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/some_path"); MockHttpServletResponse response = new MockHttpServletResponse(); ep.afterPropertiesSet();/*w ww . j a v a 2 s . com*/ ep.commence(request, response, new DisabledException("foobar")); // Check response is properly formed assertThat(response.getStatus()).isEqualTo(401); assertThat(response.getHeader("WWW-Authenticate").toString()).startsWith("Digest "); // Break up response header String header = response.getHeader("WWW-Authenticate").toString().substring(7); String[] headerEntries = StringUtils.commaDelimitedListToStringArray(header); Map<String, String> headerMap = DigestAuthUtils.splitEachArrayElementAndCreateMap(headerEntries, "=", "\""); assertThat(headerMap.get("realm")).isEqualTo("hello"); assertThat(headerMap.get("qop")).isEqualTo("auth"); assertThat(headerMap.get("stale")).isNull(); checkNonceValid(headerMap.get("nonce")); }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationEntryPointTests.java
@Test public void testOperationIfDueToStaleNonce() throws Exception { DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint(); ep.setRealmName("hello"); ep.setKey("key"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/some_path"); MockHttpServletResponse response = new MockHttpServletResponse(); ep.afterPropertiesSet();//w w w. j a va2 s .co m ep.commence(request, response, new NonceExpiredException("expired nonce")); // Check response is properly formed assertThat(response.getStatus()).isEqualTo(401); assertThat(response.getHeader("WWW-Authenticate").toString()).startsWith("Digest "); // Break up response header String header = response.getHeader("WWW-Authenticate").toString().substring(7); String[] headerEntries = StringUtils.commaDelimitedListToStringArray(header); Map<String, String> headerMap = DigestAuthUtils.splitEachArrayElementAndCreateMap(headerEntries, "=", "\""); assertThat(headerMap.get("realm")).isEqualTo("hello"); assertThat(headerMap.get("qop")).isEqualTo("auth"); assertThat(headerMap.get("stale")).isEqualTo("true"); checkNonceValid(headerMap.get("nonce")); }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationFilterTests.java
@Before public void setUp() { SecurityContextHolder.clearContext(); // Create User Details Service UserDetailsService uds = new UserDetailsService() { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return new User("rod,ok", "koala", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO")); }//ww w . ja v a 2s.co m }; DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint(); ep.setRealmName(REALM); ep.setKey(KEY); filter = new DigestAuthenticationFilter(); filter.setUserDetailsService(uds); filter.setAuthenticationEntryPoint(ep); request = new MockHttpServletRequest("GET", REQUEST_URI); request.setServletPath(REQUEST_URI); }