Java Code Examples for org.jasig.cas.TestUtils#getCredentialsWithSameUsernameAndPassword()
The following examples show how to use
org.jasig.cas.TestUtils#getCredentialsWithSameUsernameAndPassword() .
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: TicketOrCredentialPrincipalResolverTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyResolverServiceTicket() throws Exception { final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final TicketGrantingTicket ticketId = getCentralAuthenticationService() .createTicketGrantingTicket(c); final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), TestUtils.getService()); final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService()); final JoinPoint jp = mock(JoinPoint.class); when(jp.getArgs()).thenReturn(new Object[] {st.getId()}); final String result = res.resolveFrom(jp, null); assertNotNull(result); assertEquals(result, c.getId()); }
Example 2
Source File: TicketOrCredentialPrincipalResolverTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyResolverTicketGrantingTicket() throws Exception { final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final TicketGrantingTicket ticketId = getCentralAuthenticationService() .createTicketGrantingTicket(c); final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService()); final JoinPoint jp = mock(JoinPoint.class); when(jp.getArgs()).thenReturn(new Object[] {ticketId.getId()}); final String result = res.resolveFrom(jp, null); assertNotNull(result); assertEquals(result, c.getId()); }
Example 3
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyRenewWithServiceAndBadCredentials() throws Exception { final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket); request.addParameter("renew", "true"); request.addParameter("service", "test"); final Credential c2 = TestUtils.getCredentialsWithDifferentUsernameAndPassword(); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); putCredentialInRequestScope(context, c2); context.getRequestScope().put( "org.springframework.validation.BindException.credentials", new BindException(c2, "credentials")); final MessageContext messageContext = mock(MessageContext.class); assertEquals("error", this.action.submit(context, c2, messageContext).getId()); }
Example 4
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyRenewWithServiceAndDifferentCredentials() throws Exception { final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); WebUtils.putLoginTicket(context, "LOGIN"); request.addParameter("lt", "LOGIN"); WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket); request.addParameter("renew", "true"); request.addParameter("service", "test"); request.addParameter("username", "test2"); request.addParameter("password", "test2"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); final MessageContext messageContext = mock(MessageContext.class); assertEquals("success", this.action.submit(context, c, messageContext).getId()); }
Example 5
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifySuccessfulAuthenticationWithNoService() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); WebUtils.putLoginTicket(context, "LOGIN"); request.addParameter("lt", "LOGIN"); request.addParameter("username", "test"); request.addParameter("password", "test"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); putCredentialInRequestScope(context, c); final MessageContext messageContext = mock(MessageContext.class); assertEquals("success", this.action.submit(context, c, messageContext).getId()); }
Example 6
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifySuccessfulAuthenticationWithNoServiceAndWarn() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final MockRequestContext context = new MockRequestContext(); WebUtils.putLoginTicket(context, "LOGIN"); request.addParameter("lt", "LOGIN"); request.addParameter("username", "test"); request.addParameter("password", "test"); request.addParameter("warn", "true"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, response)); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); putCredentialInRequestScope(context, c); final MessageContext messageContext = mock(MessageContext.class); assertEquals("success", this.action.submit(context, c, messageContext).getId()); assertNotNull(WebUtils.getTicketGrantingTicketId(context)); assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName())); }
Example 7
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifySuccessfulAuthenticationWithServiceAndWarn() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final MockRequestContext context = new MockRequestContext(); WebUtils.putLoginTicket(context, "LOGIN"); request.addParameter("lt", "LOGIN"); request.addParameter("username", "test"); request.addParameter("password", "test"); request.addParameter("warn", "true"); request.addParameter("service", "test"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, response)); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); putCredentialInRequestScope(context, c); final MessageContext messageContext = mock(MessageContext.class); assertEquals("success", this.action.submit(context, c, messageContext).getId()); assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName())); }
Example 8
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyFailedAuthenticationWithNoService() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); request.addParameter("username", "test"); request.addParameter("password", "test2"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); putCredentialInRequestScope(context, c); context.getRequestScope().put( "org.springframework.validation.BindException.credentials", new BindException(c, "credentials")); final MessageContext messageContext = mock(MessageContext.class); assertEquals("error", this.action.submit(context, c, messageContext).getId()); }
Example 9
Source File: AuthenticationViaFormActionTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyRenewWithServiceAndSameCredentials() throws Exception { final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(c); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockRequestContext context = new MockRequestContext(); WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket); WebUtils.putLoginTicket(context, "LOGIN"); request.addParameter("lt", "LOGIN"); request.addParameter("renew", "true"); request.addParameter("service", "test"); request.addParameter("username", "test"); request.addParameter("password", "test"); context.setExternalContext(new ServletExternalContext( new MockServletContext(), request, new MockHttpServletResponse())); context.getFlowScope().put("service", TestUtils.getService()); final MessageContext messageContext = mock(MessageContext.class); assertEquals("warn", this.action.submit(context, c, messageContext).getId()); }
Example 10
Source File: PersonDirectoryPrincipalResolverTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void verifyAttributesWithPrincipal() { final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(); resolver.setAttributeRepository(TestUtils.getAttributeRepository()); resolver.setPrincipalAttributeName("cn"); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final Principal p = resolver.resolve(c); assertNotNull(p); assertNotEquals(p.getId(), TestUtils.CONST_USERNAME); assertTrue(p.getAttributes().containsKey("memberOf")); }
Example 11
Source File: QueryAndEncodeDatabaseAuthenticationHandlerTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyAuthenticationSuccessful() throws Exception { final QueryAndEncodeDatabaseAuthenticationHandler q = new QueryAndEncodeDatabaseAuthenticationHandler(this.dataSource, buildSql(), ALG_NAME); q.setNumberOfIterationsFieldName("numIterations"); q.setStaticSalt(STATIC_SALT); final UsernamePasswordCredential c = TestUtils.getCredentialsWithSameUsernameAndPassword("user1"); final HandlerResult r = q.authenticateUsernamePasswordInternal(c); assertNotNull(r); assertEquals(r.getPrincipal().getId(), "user1"); }
Example 12
Source File: PersonDirectoryPrincipalResolverTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void verifyNoAttributesWithPrincipal() { final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(); resolver.setPrincipalAttributeName(TestUtils.CONST_USERNAME); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final Principal p = resolver.resolve(c); assertNotNull(p); }
Example 13
Source File: PersonDirectoryPrincipalResolverTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
@Test public void verifyNullAttributes() { final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(); resolver.setReturnNullIfNoAttributes(true); resolver.setPrincipalAttributeName(TestUtils.CONST_USERNAME); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final Principal p = resolver.resolve(c); assertNull(p); }
Example 14
Source File: Cas30ResponseViewTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyPasswordAsAuthenticationAttributeCanDecrypt() throws Exception { final Map<?, ?> attributes = renderView(); assertTrue(attributes.containsKey(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL)); final String encodedPsw = (String) attributes.get(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL_CREDENTIAL); final String password = decryptCredential(encodedPsw); final UsernamePasswordCredential creds = TestUtils.getCredentialsWithSameUsernameAndPassword(); assertEquals(password, creds.getPassword()); }
Example 15
Source File: CacheCredentialsMetaDataPopulatorTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyAttributePopulationWithPassword() { final Authentication auth = TestUtils.getAuthentication(); final Map<String, String> map = new HashMap<>(); final CacheCredentialsMetaDataPopulator populator = new CacheCredentialsMetaDataPopulator(map); final UsernamePasswordCredential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); populator.populateAttributes(DefaultAuthenticationBuilder.newInstance(auth), c); assertTrue(map.containsKey(auth.getPrincipal().getId())); assertEquals(map.get(auth.getPrincipal().getId()), c.getPassword()); }
Example 16
Source File: TicketOrCredentialPrincipalResolverTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyResolverCredential() { final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService()); final JoinPoint jp = mock(JoinPoint.class); final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); when(jp.getArgs()).thenReturn(new Object[] {c}); final String result = res.resolveFrom(jp, null); assertNotNull(result); assertEquals(result, c.toString()); }
Example 17
Source File: CacheCredentialsMetaDataPopulatorTests.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
@Test public void verifyPasswordAsAuthenticationAttribute() { final CacheCredentialsMetaDataPopulator populator = new CacheCredentialsMetaDataPopulator(); final UsernamePasswordCredential c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final AuthenticationBuilder builder = DefaultAuthenticationBuilder.newInstance(TestUtils.getAuthentication()); populator.populateAttributes(builder, c); final Authentication authn = builder.build(); assertTrue(authn.getAttributes().containsKey(UsernamePasswordCredential.AUTHENTICATION_ATTRIBUTE_PASSWORD)); assertTrue(authn.getAttributes().get(UsernamePasswordCredential.AUTHENTICATION_ATTRIBUTE_PASSWORD) .equals(c.getPassword())); }
Example 18
Source File: MockTicketGrantingTicket.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
public MockTicketGrantingTicket(final String principal) { id = ID_GENERATOR.getNewTicketId("TGT"); final CredentialMetaData metaData = new BasicCredentialMetaData( TestUtils.getCredentialsWithSameUsernameAndPassword()); authentication = new DefaultAuthenticationBuilder(new DefaultPrincipalFactory().createPrincipal(principal)) .addCredential(metaData) .addSuccess(SimpleTestUsernamePasswordAuthenticationHandler.class.getName(), new DefaultHandlerResult(new SimpleTestUsernamePasswordAuthenticationHandler(), metaData)) .build(); created = new Date(); }