For IntelliJ IDEA,
Android Studio or Eclipse



private void myMethod () {SecurityContext s =
Message message;message.get(SecurityContext.class)
Principal p;new DefaultSecurityContext(p, subject)
SoapMessage soapMessage;soapMessage.get(SecurityContext.class)
- Smart code suggestions by Codota
}
protected String getUserName(Crypto crypto, Message message) { SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { return sc.getUserPrincipal().getName(); } return RSSecurityUtils.getUserName(crypto, null); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
@Override public void handleMessage(Message message) throws Fault { OperationInfo opinfo = getTargetOperationInfo(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (opinfo.getName() != null && authorize(sc, opinfo.getName().getLocalPart())) { return; } } else if (!isMethodProtected(opinfo.getName().getLocalPart()) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
protected boolean authorize(SecurityContext sc, String key) { List<String> expectedRoles = getExpectedRoles(key); if (expectedRoles.isEmpty()) { List<String> denyRoles = getDenyRoles(key); return denyRoles.isEmpty() ? true : isUserInRole(sc, denyRoles, true); } if (isUserInRole(sc, expectedRoles, false)) { return true; } if (LOG.isLoggable(Level.FINE)) { LOG.fine(sc.getUserPrincipal().getName() + " is not authorized"); } return false; }
@GET @Produces("text/html") public LogoutResponse logout(@CookieParam(SSOConstants.SECURITY_CONTEXT_TOKEN) Cookie context, @Context SecurityContext sc) { doLogout(context, sc); // Use View Handler to tell the user that the logout has been successful, // optionally listing the user login name and/or linking to the main application address, // the user may click on it, will be redirected to IDP and the process will start again return new LogoutResponse(sc.getUserPrincipal().getName(), mainApplicationAddress); }
private String getPrincipal(Message message) { String principal = getJAASPrincipal(); if (principal != null) { return principal; } SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { return sc.getUserPrincipal().getName(); } AuthorizationPolicy authPolicy = message.get(AuthorizationPolicy.class); if (authPolicy != null) { return authPolicy.getUserName(); } return null; }
public static UserSubject createSubject(SecurityContext securityContext) { List<String> roleNames = Collections.emptyList(); if (securityContext instanceof LoginSecurityContext) { roleNames = new ArrayList<String>(); Set<Principal> roles = ((LoginSecurityContext)securityContext).getUserRoles(); for (Principal p : roles) { roleNames.add(p.getName()); } } return new UserSubject(securityContext.getUserPrincipal().getName(), roleNames); }
protected UserSubject getGrantSubject(Message message, SamlAssertionWrapper wrapper) { SecurityContext sc = scProvider.getSecurityContext(message, wrapper); if (sc instanceof SAMLSecurityContext) { SAMLSecurityContext jaxrsSc = (SAMLSecurityContext)sc; Set<Principal> rolesP = jaxrsSc.getUserRoles(); List<String> roles = new ArrayList<>(); if (roles != null) { for (Principal p : rolesP) { roles.add(p.getName()); } } return new SamlUserSubject(jaxrsSc.getUserPrincipal().getName(), roles, jaxrsSc.getClaims()); } return new UserSubject(sc.getUserPrincipal().getName()); }
private void doLogout(Cookie context, SecurityContext sc) { if (context == null || sc.getUserPrincipal() == null || sc.getUserPrincipal().getName() == null) { reportError("MISSING_RESPONSE_STATE"); throw ExceptionUtils.toBadRequestException(null, null); } stateProvider.removeResponseState(context.getValue()); }
SecurityContext securityContext = cxfMessage.get(SecurityContext.class); if (securityContext instanceof LoginSecurityContext && ((LoginSecurityContext)securityContext).getSubject() != null) { camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, ((LoginSecurityContext)securityContext).getSubject()); } else if (securityContext != null && securityContext.getUserPrincipal() != null) { Subject subject = new Subject(); subject.getPrincipals().add(securityContext.getUserPrincipal()); camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
public void handleMessage(Message message) throws Fault { SecurityToken token = message.get(SecurityToken.class); if (token == null) { reportSecurityException("Security Token is not available on the current message"); } SecurityContext context = message.get(SecurityContext.class); if (context == null || context.getUserPrincipal() == null) { reportSecurityException("User Principal is not available on the current message"); } Subject subject = null; try { subject = createSubject(token); } catch (Exception ex) { reportSecurityException("Failed Authentication : Subject has not been created, " + ex.getMessage()); } if (subject == null || subject.getPrincipals().isEmpty()) { reportSecurityException("Failed Authentication : Invalid Subject"); } Principal principal = getPrincipal(context.getUserPrincipal(), subject); SecurityContext sc = createSecurityContext(principal, subject); message.put(SecurityContext.class, sc); }
public static UserSubject createSubject(SecurityContext securityContext) { List<String> roleNames = Collections.emptyList(); if (securityContext instanceof LoginSecurityContext) { roleNames = new ArrayList<>(); Set<Principal> roles = ((LoginSecurityContext)securityContext).getUserRoles(); for (Principal p : roles) { roleNames.add(p.getName()); } } UserSubject subject = new UserSubject(securityContext.getUserPrincipal().getName(), roleNames); Message m = JAXRSUtils.getCurrentMessage(); if (m != null && m.get(AuthenticationMethod.class) != null) { subject.setAuthenticationMethod(m.get(AuthenticationMethod.class)); } return subject; }
protected boolean authorize(SecurityContext sc, Method method) { List<String> expectedRoles = getExpectedRoles(method); if (expectedRoles.isEmpty()) { List<String> denyRoles = getDenyRoles(method); return denyRoles.isEmpty() ? true : isUserInRole(sc, denyRoles, true); } if (isUserInRole(sc, expectedRoles, false)) { return true; } if (LOG.isLoggable(Level.FINE)) { LOG.fine(sc.getUserPrincipal().getName() + " is not authorized"); } return false; } protected boolean isMethodProtected(Method method) {
public void handleMessage(Message message) throws Fault { SecurityToken token = message.get(SecurityToken.class); if (token == null) { reportSecurityException("Security Token is not available on the current message"); } SecurityContext context = message.get(SecurityContext.class); if (context == null || context.getUserPrincipal() == null) { reportSecurityException("User Principal is not available on the current message"); } Subject subject = null; try { subject = createSubject(token); } catch (Exception ex) { reportSecurityException("Failed Authentication : Subject has not been created, " + ex.getMessage()); } if (subject == null || subject.getPrincipals().size() == 0) { reportSecurityException("Failed Authentication : Invalid Subject"); } Principal principal = getPrincipal(context.getUserPrincipal(), subject); SecurityContext sc = createSecurityContext(principal, subject); message.put(SecurityContext.class, sc); }
protected String getUserName(Crypto crypto, Message message) { SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { return sc.getUserPrincipal().getName(); } return RSSecurityUtils.getUserName(crypto, null); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }
public void handleMessage(Message message) throws Fault { Method method = getTargetMethod(message); SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null) { if (authorize(sc, method)) { return; } } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) { return; } throw new AccessDeniedException("Unauthorized"); }