1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2014 Red Hat, Inc., and individual contributors
4  * as indicated by the @author tags.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */

18 package io.undertow.security.impl;
19
20 import io.undertow.security.api.AuthenticationMode;
21 import io.undertow.security.api.SecurityContext;
22 import io.undertow.security.api.SecurityContextFactory;
23 import io.undertow.security.idm.IdentityManager;
24 import io.undertow.server.HttpServerExchange;
25
26 /**
27  * <p>
28  * Default {@link io.undertow.security.api.SecurityContextFactory} implementation. It creates
29  * {@link io.undertow.security.impl.SecurityContextImpl} instances with the specified parameters, setting the
30  * programmatic mechanism name if it is not null.
31  * </p>
32  *
33  * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
34  */

35 public class SecurityContextFactoryImpl implements SecurityContextFactory {
36
37     public static final SecurityContextFactory INSTANCE = new SecurityContextFactoryImpl();
38
39     private SecurityContextFactoryImpl() {
40
41     }
42
43     @Override
44     public SecurityContext createSecurityContext(final HttpServerExchange exchange, final AuthenticationMode mode,
45         final IdentityManager identityManager, final String programmaticMechName) {
46         SecurityContextImpl securityContext = SecurityActions.createSecurityContextImpl(exchange, mode, identityManager);
47         if (programmaticMechName != null)
48             securityContext.setProgramaticMechName(programmaticMechName);
49         return securityContext;
50     }
51 }
52