generate key method & noauthprobe service modify

This commit is contained in:
geek 2018-03-27 19:00:05 +09:00
parent 497785553d
commit 0b5ca8ee7b
4 changed files with 81 additions and 8 deletions

View File

@ -32,6 +32,7 @@
<apache.velocity.version>1.7</apache.velocity.version>
<docker.registry.name>docker.loafle.net/overflow</docker.registry.name>
<googleauth.version>1.1.2</googleauth.version>
<fasterxml.uuid.verion>3.1.5</fasterxml.uuid.verion>
</properties>
<dependencies>
@ -181,6 +182,12 @@
<artifactId>googleauth</artifactId>
<version>${googleauth.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>${ fasterxml.uuid.verion }</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,25 @@
package com.loafle.overflow.commons.utils;
import com.fasterxml.uuid.EthernetAddress;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;
/**
* Created by geek on 18. 3. 27.
*/
public class GenerateKey {
private static TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
public static synchronized String getKey() {
String[] uuids = generator.generate().toString().split("-");
StringBuffer sb = new StringBuffer();
for ( int idx = 0; idx < uuids.length; idx++ ) {
sb.append(uuids[idx]);
}
return sb.toString();
}
}

View File

@ -1,12 +1,17 @@
package com.loafle.overflow.module.noauthprobe.service;
import com.loafle.overflow.commons.model.SessionMetadata;
import com.loafle.overflow.commons.service.MessagePublisher;
import com.loafle.overflow.commons.stereotype.ProbeAPI;
import com.loafle.overflow.commons.stereotype.WebappAPI;
import com.loafle.overflow.commons.utils.GenerateKey;
import com.loafle.overflow.module.apikey.model.ApiKey;
import com.loafle.overflow.module.apikey.service.ApiKeyService;
import com.loafle.overflow.module.domain.model.Domain;
import com.loafle.overflow.module.domain.model.DomainMember;
import com.loafle.overflow.module.domain.service.DomainMemberService;
import com.loafle.overflow.module.member.model.Member;
import com.loafle.overflow.module.member.service.MemberService;
import com.loafle.overflow.module.meta.model.MetaNoAuthProbeStatus;
import com.loafle.overflow.module.meta.model.MetaProbeStatus;
import com.loafle.overflow.module.noauthprobe.dao.NoAuthProbeDAO;
@ -46,15 +51,18 @@ public class NoAuthProbeService {
@Autowired
private MessagePublisher messagePublisher;
@Autowired
private DomainMemberService domainMemberService;
@ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) {
noAuthProbe.setTempProbeKey(UUID.randomUUID().toString());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short)3));
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
noAuthProbe.setDomain(apiKey.getDomain());
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short)3));
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
return this.noAuthProbeDAO.save(noAuthProbe);
@ -72,18 +80,22 @@ public class NoAuthProbeService {
@WebappAPI
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException {
String memberEmail = SessionMetadata.getTargetID();
// Todo domain injection & member injection
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
Probe probe = new Probe();
probe.setEncryptionKey(encryptKey);
probe.setProbeKey(noAuthProbe.getApiKey());
probe.setDomain(new Domain(1));
probe.setAuthorizeMember(new Member(1));
probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
probe.setStatus(new MetaProbeStatus((short)1));
Map<String, Object> objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<HashMap<String,Object>>() {});
@ -114,6 +126,7 @@ public class NoAuthProbeService {
@WebappAPI
public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) {
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");

View File

@ -858,6 +858,12 @@ INSERT INTO public.meta_history_type (id,create_date,"name") VALUES (
INSERT INTO public."member" (company_name,create_date,email,"name",phone,pw,status_id) VALUES (
'loafle','2017-06-26 11:07:27.625','overflow@loafle.com','overFlow','000-000-0000','$2a$10$G2bbjoX9.fOnxJx/8DZqPujFYrEQtIEB.f98/8K20XiGWEhwPakZ.',2);
INSERT INTO public."member" (company_name,create_date,email,"name",phone,pw,status_id) VALUES (
'loafle','2017-06-26 11:07:27.625','insanity@loafle.com','overFlow','000-000-0000','$2a$10$G2bbjoX9.fOnxJx/8DZqPujFYrEQtIEB.f98/8K20XiGWEhwPakZ.',2);
INSERT INTO public."member" (company_name,create_date,email,"name",phone,pw,status_id) VALUES (
'loafle','2017-06-26 11:07:27.625','snoop@loafle.com','overFlow','000-000-0000','$2a$10$G2bbjoX9.fOnxJx/8DZqPujFYrEQtIEB.f98/8K20XiGWEhwPakZ.',2);
INSERT INTO public."member" (company_name,create_date,email,"name",phone,pw,status_id) VALUES (
'loafle','2017-06-26 11:07:27.625','geekdev@naver.com','geek','000-000-0000','$2a$10$G2bbjoX9.fOnxJx/8DZqPujFYrEQtIEB.f98/8K20XiGWEhwPakZ.',2);
@ -870,10 +876,23 @@ INSERT INTO public.email_auth (auth_confirm_date,create_date,email_auth_key,memb
INSERT INTO public."domain" (create_date,"name") VALUES (
'2017-06-26 11:25:44.866','overFlow''s domain');
INSERT INTO public."domain" (create_date,"name") VALUES (
'2017-06-26 11:25:44.866','insanity''s domain');
INSERT INTO public."domain" (create_date,"name") VALUES (
'2017-06-26 11:25:44.866','snoop''s domain');
INSERT INTO public."domain" (create_date,"name") VALUES (
'2017-06-26 11:25:44.866','geek''s domain');
INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES (
'2017-06-26 11:27:43.023',1,1);
INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES (
'2017-06-26 11:27:43.023',1,2);
'2017-06-26 11:27:43.023',2,2);
INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES (
'2017-06-26 11:27:43.023',3,3);
INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES (
'2017-06-26 11:27:43.023',4,4);
-- Member TOTP Insert SQL
-- INSERT INTO public.member_totp (create_date, secret_code, update_date, member_id) VALUES(
@ -884,6 +903,15 @@ INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES (
INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES (
'52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1);
INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES (
'bf78f1f4319611e897713222d3c76cf6','2017-06-26 13:02:28.347',2);
INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES (
'05cf2947319911e898993222d3c76cf6','2017-06-26 13:02:28.347',3);
INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES (
'09c8c54f319911e8a41f3222d3c76cf6','2017-06-26 13:02:28.347',4);
INSERT INTO public.probe (authorize_date,cidr,create_date,description,display_name,encryption_key,probe_key,authorize_member_id,domain_id,status) VALUES (
'2017-08-21 14:48:31.563','192.168.1.0/24','2017-08-21 14:48:31.563','snoop probe','test probe 111111','8c51fa9c5bcc11e7980a080027658d13','899fdd145bcc11e7b611080027658d13',1,1,1);