List of usage examples for org.apache.shiro.authz UnauthenticatedException UnauthenticatedException
public UnauthenticatedException()
From source file:com.epimorphics.registry.security.BaseUserStore.java
License:Apache License
private void checkSubjectIs(String id) { try {/* w w w . java 2s.c o m*/ Subject subject = SecurityUtils.getSubject(); if (subject.isAuthenticated()) { if (id.equals(((UserInfo) subject.getPrincipal()).getOpenid()) || subject.hasRole(RegAuthorizationInfo.ADMINSTRATOR_ROLE)) { return; } else { throw new AuthorizationException("Cannot change credentials for another user"); } } else { throw new UnauthenticatedException(); } } catch (UnavailableSecurityManagerException e) { // Allow to proceed if no security system is configured } }
From source file:com.epimorphics.registry.security.BaseUserStore.java
License:Apache License
private void checkSubjectControls(String path) { try {/*from w ww . java2 s .c om*/ Subject subject = SecurityUtils.getSubject(); if (!subject.isAuthenticated()) { throw new UnauthenticatedException(); } subject.checkPermission("Grant:" + path); } catch (UnavailableSecurityManagerException e) { // Allow to proceed if no security system is configured } }
From source file:com.epimorphics.registry.security.BaseUserStore.java
License:Apache License
private void checkIsAdministrator() { try {/*from w w w. j a v a 2 s . co m*/ Subject subject = SecurityUtils.getSubject(); if (!subject.isAuthenticated()) { throw new UnauthenticatedException(); } if (!subject.hasRole(RegAuthorizationInfo.ADMINSTRATOR_ROLE)) { throw new UnauthorizedException("You must be an administrator to do this"); } } catch (UnavailableSecurityManagerException e) { // Allow to proceed if no security system is configured } }
From source file:fiftyfive.wicket.shiro.ShiroWicketPluginTest.java
License:Apache License
@Test public void testUnauthenticatedRedirectsToLogin_exception() throws Exception { mockGuest();/* w w w. j a va 2 s . c o m*/ this.tester.startPage(new ExceptionalPage(new UnauthenticatedException())); assertRedirectsToLogin(); }
From source file:org.apache.aurora.scheduler.http.api.security.ShiroAuthenticatingThriftInterceptor.java
License:Apache License
@Override public Object invoke(MethodInvocation invocation) throws Throwable { checkState(initialized);/*from w w w.j a v a 2 s.com*/ Subject subject = subjectProvider.get(); if (subject.isAuthenticated()) { return invocation.proceed(); } else { // This is a special exception that will signal the BasicHttpAuthenticationFilter to send // a 401 with a challenge. This is necessary at this layer since we only apply this // interceptor to methods that require authentication. throw new UnauthenticatedException(); } }
From source file:org.apache.aurora.scheduler.http.api.security.ShiroKerberosPermissiveAuthenticationFilterTest.java
License:Apache License
@Test public void testInterceptsUnauthenticatedException() throws ServletException, IOException { mockServlet.service(anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall().andThrow(new UnauthenticatedException()); replayAndStart();/* w w w .ja va2s. c om*/ ClientResponse clientResponse = getRequestBuilder(PATH).get(ClientResponse.class); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, clientResponse.getStatus()); assertEquals(ShiroKerberosAuthenticationFilter.NEGOTIATE, clientResponse.getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE)); }
From source file:org.apache.aurora.scheduler.http.api.security.ShiroThriftInterceptor.java
License:Apache License
@Override public Object invoke(MethodInvocation invocation) throws Throwable { checkState(initialized);// w ww . j a v a 2 s . c o m Subject subject = subjectProvider.get(); if (!subject.isAuthenticated()) { // This is a special exception that will signal the BasicHttpAuthenticationFilter to send // a 401 with a challenge. This is necessary at this layer since we only apply this // interceptor to methods that require authentication. throw new UnauthenticatedException(); } Permission checkedPermission = new WildcardPermission( PERMISSION_JOINER.join(permissionPrefix, invocation.getMethod().getName())); if (subject.isPermitted(checkedPermission)) { return invocation.proceed(); } else { shiroAuthorizationFailures.incrementAndGet(); String responseMessage = "Subject " + subject.getPrincipal() + " lacks permission " + checkedPermission; LOG.warning(responseMessage); // TODO(ksweeney): 403 FORBIDDEN would be a more accurate translation of this response code. return Responses.addMessage(Responses.empty(), ResponseCode.AUTH_FAILED, responseMessage); } }
From source file:uk.co.q3c.v7.base.shiro.V7ErrorHandlerTest.java
License:Apache License
@Test public void authentication() { // given// w w w.jav a 2 s.c o m Throwable exception = new UnauthenticatedException(); when(event.getThrowable()).thenReturn(exception); // when handler.error(event); // then verify(authenticationHandler).invoke(); }